gpt4 book ai didi

google-apps-script - copyTo 使用 {contentsOnly :true} not working

转载 作者:行者123 更新时间:2023-12-02 01:13:13 28 4
gpt4 key购买 nike

请注意,我对 Google Apps 脚本编写还很陌生。我很感激能提供的任何帮助。

我正在尝试将工作表的内容复制到新文档中。这段代码没有任何问题:

// Create a new Spreadsheet and copy the current sheet into it.
var newSpreadsheet = SpreadsheetApp.create("Spreadsheet to export");
var projectname = SpreadsheetApp.getActiveSpreadsheet();
sheet = originalSpreadsheet.getActiveSheet();
sheet.copyTo(newSpreadsheet);

但是,这会复制当前工作表中的公式 - 我试图仅复制值,因为公式引用了原始文档中其他工作表上的数据。

我的尝试如下:

// Create a new Spreadsheet and copy the current sheet into it.
var newSpreadsheet = SpreadsheetApp.create("Spreadsheet to export");
var projectname = SpreadsheetApp.getActiveSpreadsheet();
sheet = originalSpreadsheet.getActiveSheet();
sheet.copyTo(newSpreadsheet, {contentsOnly:true})

但是,这会产生以下错误:找不到方法(类)copyTo($Proxy914,object)。

我不确定我做错了什么。任何援助将不胜感激。提前致谢!

最佳答案

实际上有2个copyTo,一个applies to sheet和另一个applies to Range

根据文档(见上面的链接),第二个有可选参数来仅复制值,而第一个没有。

我猜你可以做的是使用 Range.copyTo() 将整个工作表范围复制到一个临时工作表(在同一个电子表格中),然后将该临时工作表复制到另一个电子表格最后从源电子表格中删除临时工作表。

希望它足够清楚 ;-)

关于google-apps-script - copyTo 使用 {contentsOnly :true} not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14864831/

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