我正在尝试在完成复制后更新新复制的文档,将其添加到不同的文件夹并删除其根文件。Google 脚本无法找到新复制的文件。错误位于代码的下半部分,由带有 TypeError 的星号包围。
我怀疑它与var doc = DocumentApp.getActiveDocument();
. 我不确定如何获取新复制文档的 URL(file2
或Date - Weekly Agenda
)。
function copyupdateWeeklyAgenda() {
var file = DriveApp.getFileById("FILEKEY");
var source_folder = DriveApp.getFolderById("FOLDERKEY");
var dest_folder = DriveApp.getFolderById("FOLDERKEY");
// Make a backup copy.
var file2 = file.makeCopy('Date - Weekly Agenda');
dest_folder.addFile(file2);
source_folder.removeFile(file2);
//START Update Weekly Agenda Data ---
var ssUrl = 'https://whydoyouwanttoknow.com';
var sheetName = 'Sheet1'; // name of sheet to use
var rangeName = 'A1:B2'; // range of values to include
var values = SpreadsheetApp.openByUrl(ssUrl)
.getSheetByName(sheetName)
.getRange(rangeName)
.getValues();
var doc = DocumentApp.getActiveDocument();
**var body = doc.getBody();** <--- TYPEERROR: Cannot call method "getBody" of null.
var ranges = doc.getNamedRanges('embeddedSheet-range');
if (ranges.length == 0) {
var table = body.appendTable(values);
...ETC.