【发布时间】:2017-12-14 07:01:38
【问题描述】:
我正在尝试使用 Google Apps 脚本 copy() 将我的主电子表格“发布”到输出电子表格,但每次都会获得多个副本,而不是替换输出文件。谁能建议一种方法来替换目标电子表格的内容,以便我可以为输出保留相同的文件 ID 并手动触发“发布”。尝试过copyTo,但只是制作了多张纸。
主电子表格是一个员工名册,需要多个经理在没有员工看到实时版本的情况下进行处理。经理完成更新后,可以推送给员工。
编辑:搞定了
function publishRoster() {
var source = SpreadsheetApp.getActiveSpreadsheet();
var sheet = source.getActiveSheet();
var updatedDateTime = sheet.getRange("A1");
var now = Utilities.formatDate(new Date(), "GMT+10:30", "dd/MM/yyyy H:mm")
updatedDateTime.setValue("Last Published " + now);
var sourceName = source.getSheetName();
// var sValues = source.getDataRange().getValues();
var destination = SpreadsheetApp.openById('my-destination-sheet-id-here');
var destinationSheet = destination.getSheetByName(sourceName);
if (destinationSheet == null ) { }
else { destination.deleteSheet(destinationSheet); }
sheet.copyTo(destination).setName(sourceName);
}
【问题讨论】:
标签: google-apps-script google-sheets