【发布时间】:2017-04-18 07:10:48
【问题描述】:
我正在使用 google 电子表格 API 使用 node.js 创建电子表格。我想在创建电子表格时添加一个标题(具有三列 h1、h2、h3)。我可以创建电子表格,但无法添加标题。有什么选择吗?
【问题讨论】:
标签: api google-sheets header add google-spreadsheet-api
我正在使用 google 电子表格 API 使用 node.js 创建电子表格。我想在创建电子表格时添加一个标题(具有三列 h1、h2、h3)。我可以创建电子表格,但无法添加标题。有什么选择吗?
【问题讨论】:
标签: api google-sheets header add google-spreadsheet-api
下面的 GAS 样本怎么样?如果你想运行 GAS 以外的东西,请告诉我。
若要使用此功能,请先启用 Advanced Google services 和 Google API Console 的 Google Sheet API v4。
使用方法如下。
在脚本编辑器中,选择资源 > 高级 Google 服务
在出现的对话框中,点击 Google Sheets API 的开/关开关。
在对话框底部,单击 Google API 控制台的链接。
在控制台中,点击过滤器框并输入 API 的部分名称“Google Sheets API”,然后在看到名称后点击该名称。
在下一个屏幕上,点击启用 API。
关闭开发者控制台并返回脚本编辑器。在对话框中单击确定。您启用的高级服务现在可以自动完成。
详细信息为https://developers.google.com/apps-script/guides/services/advanced。
脚本:
Sheets.Spreadsheets.create({
"properties":
{
"title": "filename" // filename
},
"sheets":
[
{
"data":
[
{
"startRow": 0, // 1st row
"startColumn": 7, // column h
"rowData":
[
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "sample text h1"
}
}
]
},
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "sample text h2"
}
}
]
},
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "sample text h3"
}
}
]
}
]
}
]
}
]
});
结果:
很抱歉 JSON 数据太长。请更改示例文本。如果要为单元格使用数字,请使用"numberValue" 而不是"stringValue"。
如果我误解了你的问题,我很抱歉。
添加了 1 个:
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getRange('h1:h3');
var protection = range.protect().setDescription('protected');
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
以上脚本保护h1:h3。所有者可以编辑所有单元格,但其他用户不能只编辑h1:h3。
添加了 2 个:
Sheets.Spreadsheets.create({
"properties":
{
"title": "filename"
},
"sheets":
[
{
"protectedRanges":
[
{
"range":
{
"startColumnIndex": 7,
"endColumnIndex": 8,
"startRowIndex": 0,
"endRowIndex": 3,
"sheetId": 0
},
"description": "protected",
"editors":
{
"users":
["your e-mail address"
]
}
}
],
"data":
[
{
"startColumn": 7,
"startRow": 0,
"rowData":
[
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "sample text h1"
}
}
]
},
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "sample text h2"
}
}
]
},
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "sample text h3"
}
}
]
}
]
}
],
"properties":
{
"sheetId": 0
}
}
]
});
此脚本创建新的电子表格。那时,它将数据添加到 'h1:h3' 并保护它们。请添加您的电子邮件地址作为编辑。这是使用的 Google Sheet API v4。
【讨论】:
h1:h3。