2017-01-23 60 views
0

這是代碼。由於調查對象提交表單時使用觸發器,因此我無法進行調試。如何通過google apps腳本保存文檔?

// This code opens the doc and names it what you wanted it named above. It also appends any other language to the title that you wish. My sample below will title each document as docName + 'for' + Lname or (OA Graduate Assistant Application for Last Name of user). 
    var copyId = DriveApp.getFileById(docTemplate) 
    .makeCopy(docName+' for '+ Lname) 
    .getId(); 

    // Open the temporary document 
    var copyDoc = DocumentApp.openById(copyId); 

    // Get the document’s body section 
    var copyBody = copyDoc.getActiveSection(); 

    //code that makes edits 
    copyBody.replaceText('keyTimestamp', Timestamp); 
    copyBody.replaceText('keyPemail', Pemail); 

//define the source folder to save the file in 
    var dir = DriveApp.getFolderById(folderid); 

//add this file to the source folder 
    dir.addFile(copyDoc); 


    copyDoc.saveAndClose(); 

沒有文件存儲在指定的文件夾和我的整個谷歌驅動器。有什麼問題?所有的變量都被正確定義(我只是省略了var語句)。

+0

是值被傳遞給[getFileById(ID)](https://developers.google.com/apps-script/reference/drive/drive-app#getfilebyidid),一個有效驅動器的文件ID? – noogui

+0

是該文件是有效 – NoMoreErrors

+0

有沒有辦法如果沒有發生的事情,我可以調試此問題 – NoMoreErrors

回答

0

如何下面的腳本?

「addFile()」 是類DriveApp的方法。所以文件必須通過DriveApp的方法來檢索。對於你的腳本,它使用「getFileById()」。

// This code opens the doc and names it what you wanted it named above. It also appends any other language to the title that you wish. My sample below will title each document as docName + 'for' + Lname or (OA Graduate Assistant Application for Last Name of user). 
var copyId = DriveApp.getFileById(docTemplate) 
.makeCopy(docName+' for '+ Lname) 
.getId(); 

// Open the temporary document 
var copyDoc = DocumentApp.openById(copyId); 

// Get the document’s body section 
var copyBody = copyDoc.getActiveSection(); 

//code that makes edits 
copyBody.replaceText('keyTimestamp', Timestamp); 
copyBody.replaceText('keyPemail', Pemail); 

//define the source folder to save the file in 
var dir = DriveApp.getFolderById(folderid); 

//add this file to the source folder 
dir.addFile(DriveApp.getFileById(copyId)); 


copyDoc.saveAndClose(); 

如果這沒有解決方案,我很抱歉。

+0

抱歉,這是行不通的。 – NoMoreErrors

+0

我可以問你關於錯誤嗎? – Tanaike

相關問題