【发布时间】:2017-08-11 02:20:49
【问题描述】:
这是我第一次尝试使用脚本编辑器。我被分配做一个脚本来为谷歌工作表创建数据透视表。
//creating pivot table through script editor for google sheet
function addPivotTable() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetName = "Sheet1";
// Create a new sheet which will contain our Pivot Table
var pivotTableSheet = ss.insertSheet();
var pivotTableSheetId = pivotTableSheet.getSheetId();
// Add Pivot Table to new sheet
// Meaning we send an 'updateCells' request to the Sheets API
// Specifying via 'start' the sheet where we want to place our Pivot Table
// And in 'rows' the parameters of our Pivot Table
var requests = [{
// Meaning we send an 'updateCells' request to the Sheets API
"updateCells": {
// And in 'rows' the parameters of our Pivot Table
"rows": {
"values": [
{
// Add Pivot Table to new sheet
"pivotTable": {
"source": {
"sheetId": ss.getSheetByName(sheetName).getSheetId(),
"startRowIndex": 0,
"startColumnIndex": 0,
},
//create rows from the selected columns
"rows": [
{
"sourceColumnOffset": 14,
"showTotals": true,
"sortOrder": "ASCENDING",
},
],
//show values from the selected columns
"values": [
{
"summarizeFunction": "COUNTA",
"sourceColumnOffset": 10
}
],
//display in horizontal layout
"valueLayout": "HORIZONTAL"
}
}
]
},
// Specifying via 'start' the sheet where we want to place our Pivot Table
"start": {
"sheetId": pivotTableSheetId,
},
"fields": "pivotTable"
}
}];
Sheets.Spreadsheets.batchUpdate({'requests': [requests]}, ss.getId());
}
请检查我的代码并解释我哪里出错了,因为每次我运行脚本编辑器时都会出错,提示表单未定义弹出窗口。 "ReferenceError: "Sheets" 未定义。(第 46 行,文件 "Code")Dismiss"
【问题讨论】:
-
剂量表从何而来?它是全局 Obj 然后检查它是否存在并加载。你可以安慰它来确认它
标签: javascript json google-sheets