ReferenceError:未定义"表格"

Mok*_*lan 5 javascript json google-sheets

这是我第一次使用脚本编辑器.我被分配做一个脚本来为谷歌表格的数据透视表.

  //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());
}
Run Code Online (Sandbox Code Playgroud)

请检查我的代码,并解释我每次运行脚本编辑器时出错的地方错误说明表没有定义弹出窗口."ReferenceError:"Sheets"未定义.(第46行,文件"Code")Dismiss"

Plu*_*uto 8

这是来自谷歌的高级服务.您需要在使用之前启用此服务. https://developers.google.com/apps-script/guides/services/advanced 在脚本编辑器中,选择资源>高级Google服务....在出现的对话框中,单击服务旁边的开/关开关你想用.在对话框的底部,点击Google API控制台的链接.在控制台中,单击过滤器框并键入API名称的一部分(例如,"日历"),然后在看到名称后单击该名称.在下一个屏幕上,单击"启用API".关闭API控制台并返回脚本编辑器.在对话框中单击"确定".您启用的高级服务现在可以在自动填充中使用.

  • 您需要启用“Google Sheets API”服务 (3认同)

小智 8

只需从此处添加所需的服务即可,如果您需要 Google Sheets API。祝你好运。

只需从这里添加服务即可,祝你好运