问题描述
希望这个问题还没有得到解答.我花了大量时间进行搜索,虽然我找到了类似的帖子,但没有一个完全符合我的意图.
Hopefully this question has not already been answered. I have spent a considerable amount of time searching, and although I have found similar posts, none have done exactly what I am trying to do.
我想使用 Google Apps 脚本将 Google 电子表格中的单个工作表复制到另一个 Google 电子表格中,并且我想保留格式(包括合并的单元格).有没有办法做到这一点?我尝试了以下功能:
I would like to use Google Apps Script to copy a single sheet from a Google spreadsheet into a different Google spreadsheet, and I want to retain formatting (including merged cells). Is there any way to do this? I have tried the following functions:
复制到()copyFormatToRange()
copyTo()copyFormatToRange()
但这些方法仅适用于同一个电子表格,并且不允许在不同电子表格之间复制数据.有没有人有什么建议?谢谢!
but these methods only work within the same spreadsheet and do not allow data to be copied between different spreadsheets. Does anyone have any suggestions? Thanks!
推荐答案
您是否看过此处:
https://developers.google.com/apps-script/reference/电子表格/工作表#copyTo(电子表格)
copyTo(电子表格)
copyTo(spreadsheet)
将工作表复制到另一个电子表格.目标电子表格可以是源.新电子表格的名称为[原始电子表格名称] 的副本".
Copies the sheet to another spreadsheet. The destination spreadsheet can be the source. The new spreadsheet will have the name "Copy of [original spreadsheet name]".
var source = SpreadsheetApp.getActiveSpreadsheet();
var sheet = source.getSheets()[0];
var destination = SpreadsheetApp.openById("ID_GOES HERE");
sheet.copyTo(destination);
这篇关于Google Apps Script,使用格式将一个电子表格复制到另一个电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!