我正在根据模板创建几个 doc.file,并从工作表中获取数据。所有内容都保存在不同的文件中。请帮我把这些新文件保存到一个文档中。
function myFunction() {
const docFile = DriveApp.getFileById("....."); //template file
const tempFolder = DriveApp.getFolderById("...."); //folder for new files
var list = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); //get an active book, get an asset.sheet
var l = list.getLastRow(); // get the last line
for (var i = 9; i <= l; i++) {
const tempFile = docFile.makeCopy(tempFolder);//make a copy of the template
const tempDocFile = DocumentApp.openById(tempFile.getId()); //open a copy of the template
const body = tempDocFile.getBody(); //get the body (text) of the copy file
//getting variables from the table::
var a1 = list.getRange(i, 1).getValue(); // get data from drain number i and column 1 -
var a2 = list.getRange(i, 2).getValue();
var a3 = list.getRange(i, 3).getValue();
//replacing the necessary data in the text of the template copies:
body.replaceText("{......}", a1);
body.replaceText("{.....}", a2);
body.replaceText("{....}", a3);
//naming the created file:
const newFileName = '.....' + a2; // assigning a name
tempFile.setName(newFileName);
tempDocFile.saveAndClose(); //save and close
}
}
我不是程序员,在网上找了个脚本自己改了一下,不知道具体怎么改。