gpt4 book ai didi

google-apps-script - 谷歌脚本仅粘贴值

转载 作者:行者123 更新时间:2023-12-04 03:20:17 28 4
gpt4 key购买 nike

将工作表复制到新电子表格时我需要帮助。我只想粘贴值。

我正在从工作表的副本创建 .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});

最佳答案

在此文档中,您可以在此处查看如何正确使用函数 copyTo(spreadsheet) .这是示例代码。

 var source = SpreadsheetApp.getActiveSpreadsheet();
var sheet = source.getSheets()[0];

var destination = SpreadsheetApp.openById('ID_GOES HERE');
sheet.copyTo(destination);

copyTo(destination, options)

 // 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 .

关于google-apps-script - 谷歌脚本仅粘贴值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38839784/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com