将表格复制到新的电子表格时我需要帮助。我想只粘贴值。
我正在从工作表副本创建.pdf,但CopyTo也是从工作表中复制的公式。
function topdf() {
var foldersave = DriveApp.getFolderById('ID');
var originalSpreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Print_sheet_Damir");
var radni_sheet_Damir = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Radni_sheet_Damir");
var name = originalSpreadsheet.getRange("C4").getValue();
var ID = radni_sheet_Damir.getRange("E2").getValue();
var newSpreadsheet = SpreadsheetApp.create("ID_" + ID + "_" + name);
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var projectname = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Print_sheet_Damir");
sheet.copyTo((newSpreadsheet), {contentsOnly: true});
newSpreadsheet.getSheetByName('Sheet1').activate();
newSpreadsheet.deleteActiveSheet();
pdf = newSpreadsheet.getBlob();
var file = foldersave.createFile(pdf);
但以下这行不适合我:
sheet.copyTo((newSpreadsheet), {contentsOnly: true});
答案 0 :(得分:1)
在此文档中,您可以在此处查看如何正确使用函数copyTo(spreadsheet)。这是示例代码。
var source = SpreadsheetApp.getActiveSpreadsheet();
var sheet = source.getSheets()[0];
var destination = SpreadsheetApp.openById('ID_GOES HERE');
sheet.copyTo(destination);
// The code below will copy only the values of the first 5 columns over to the 6th column.
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange("A:E").copyTo(sheet.getRange("F1"), {contentsOnly:true});
}
您还可以查看tutorial有关如何将电子表格值复制到其他电子表格的信息。
有关详情,请查看Google AppsScript documentation for Spreadsheet及其相关的SO question。
答案 1 :(得分:0)
您应该在这一行中使用 getRange():
sheet.copyTo((newSpreadsheet), {contentsOnly: true});
它应该看起来像这样:
sheet.copyTo(newSpreadsheet.getRange("The range you want to work with"), {contentsOnly: true});