如何创建电子表格并将其自动打开 [英] How can I create spreadsheet and open it Automaticclly
问题描述
我有一个电子表格模型,我想自动将此模型中的工作表复制到新的电子表格中(不在同一电子表格中)。
此新电子表格必须自动打开并保存在我的Google云端硬盘中。我该如何做到这一点?
我从这段代码开始,但它不起作用
函数CreateReports()
{
var ssNew = SpreadsheetApp.create(date);
var url = ssNew.getUrl()
var ss = SpreadsheetApp.openByUrl(url);
Logger.log(ssNew.getUrl());
解决方案如果你想要复制整个电子表格,请参阅文档中的示例 Spreadsheet.copy()
。
此脚本将:
- 创建一个由当前日期命名的新电子表格。
- 将模型表复制到新电子表格中
- 重新命名已复制的模型表(再次使用当前日期)
- 返回新的图表对象(如果您愿意,则打开它)
$ b $ h3> code
函数copyModel(){
//获取今天的日期作为字符串
var date =(new Date())。toDateString();
//获取我们的模型图
var source = SpreadsheetApp.getActiveSpreadsheet();
var model = source.getSheetByName(model);
//在云端硬盘上创建一个新的电子表格,按日期命名
var destination = SpreadsheetApp.create(date);
//将模型图复制并重新命名为新的电子表格
var newSheet = model.copyTo(destination).setName(date);
返回newSheet;
}
I have a model of spreadsheet, and I want to automatically duplicate the sheet in this model to a new spreadsheet (not in the same spreadsheet).
This new spreadsheet must be automatically opened and saved in my Google Drive. How can I do this?
I started with this code but it doesn't work
function CreateReports()
{
var ssNew = SpreadsheetApp.create(date);
var url = ssNew.getUrl()
var ss = SpreadsheetApp.openByUrl(url);
Logger.log(ssNew.getUrl());
}
解决方案 If you want to duplicate the entire spreadsheet, see the example in the documentation for Spreadsheet.copy()
.
This script will:
- Create a new spreadsheet, named by the current date.
- Copy the model sheet to the new spreadsheet
- Rename the copied model sheet (again, with current date)
- Return the new Sheet Object ("opens" it, if you will)
code
function copyModel() {
// Get today's date as a string
var date = (new Date()).toDateString();
// Get our model sheet
var source = SpreadsheetApp.getActiveSpreadsheet();
var model = source.getSheetByName("model");
// Create a new spreadsheet on Drive, named by date
var destination = SpreadsheetApp.create(date);
// Copy and rename the model sheet into new spreadsheet
var newSheet = model.copyTo(destination).setName(date);
return newSheet;
}
这篇关于如何创建电子表格并将其自动打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!