如何删除PDF的两个第二副本

时间:2019-02-03 05:27:35

标签: google-apps-script

我使用此代码生成pdf文件,并将其保存在发票的文件夹中,但是它将所有文件夹中的两个副本保存在该文件夹中,一个保存在google drive中,如何在驱动器中删除pdf发送副本,但是不在文件夹中。 代码是

function runBothfunctions(){
//function 1
var ss = SpreadsheetApp.getActiveSpreadsheet()
var ss1 = ss.getSheetByName('sheet1')
var ss1Id = ss1.getSheetId()
var ss2 = ss.getSheetByName('sheet2')
var ssId = ss.getId()
var clientName = ss1.getRange(3,3).getValue()
var invoiceNumber = ss1.getRange(4,3).getValue()
var totalBill = ss1.getRange(29,9).getValue()
var d = new Date();
var fullDate = ('0' + d.getDate()).slice(-2) +"/"+ ('0' + (d.getMonth()    +1)).slice(-2) +"/"+ (d.getYear().toString()).slice(-2)
var invoiceFileName = invoiceNumber + '_' + fullDate + '_' + clientName +'_'+ totalBill

var url = ss.getUrl()
url = url.replace(/edit$/,'')
var url_ext = 'export?exportFormat=pdf&format=pdf'
+ '&size=A4'                           // paper    size: "legal" / "letter" / "A4"
+ '&fitw=true'                         // fit to width, false for actual size
+ '&sheetnames=false&printtitle=false' // hide optional headers and footers
+ '&gridlines=false'                   // hide gridlines
+ '&gid=' + ss1Id                      // the sheet's Id

var token = ScriptApp.getOAuthToken()  
// Convert sheet1 to PDF
var response = UrlFetchApp.fetch(url + url_ext, { headers:   { 'Authorization': 'Bearer ' +  token }})

var blob = response.getBlob().setName(invoiceFileName + '.pdf')  
 // Add the folder ID of the Drive folder where the PDF should be saved.   Create a folder and copy this ID: www.goo.gl/TfgqrN
var invoiceURL = DriveApp.getFolderById('19_cTkcDHlekS-  7Y32BEzUVlhghC0UHMZ').createFile(blob).getUrl()
 ss2.getRange(ss2.getLastRow() +1, 1).setFormula('=HYPERLINK("' +   invoiceURL + '";"' + invoiceFileName + '")')

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();

//create an array of the invoice numbers already created 
var colArray = sheet.getRange(4, 3).getValues();

//sort the array values to find max
var maxInColumn = colArray.sort(function(a,b){return b-a})[0][

0 个答案:

没有答案