2017-01-23 59 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

相关问题