Google Apps脚本,使用格式将一个电子表格复制到另一个电子表格 [英] Google Apps Script, copy one spreadsheet to another spreadsheet with formatting

查看:102
本文介绍了Google Apps脚本,使用格式将一个电子表格复制到另一个电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望这个问题还没有得到解答。我花了大量的时间搜索,尽管我发现了类似的帖子,但没有一个完成了我正在尝试做的事。



我想使用Google Apps脚本将Google电子表格中的单个工作表复制到另一个Google电子表格中,并且我希望保留格式(包括合并的单元格)。有没有办法做到这一点?我已经尝试了以下功能:

copyTo()
copyFormatToRange()


只能在同一电子表格内工作,并且不允许在不同电子表格之间复制数据。有没有人有什么建议?谢谢!

解决方案

你看过这里:
$ b https://developers.google.com/apps-script/reference/spreadsheet/sheet#copyTo( Spreadsheet)



copyTo(电子表格)



将工作表复制到另一个电子表格。目标电子表格可以是源代码。新电子表格的名称将为原始电子表格名称的副本。

  var source = SpreadsheetApp.getActiveSpreadsheet(); 

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

var destination = SpreadsheetApp.openById(ID_GOES HERE);

sheet.copyTo(destination);


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.

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:

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!

解决方案

Have you looked here:

https://developers.google.com/apps-script/reference/spreadsheet/sheet#copyTo(Spreadsheet)

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脚本,使用格式将一个电子表格复制到另一个电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆