ReferenceError:“Sheets”没有定义 [英] ReferenceError: "Sheets" is not defined

查看:117
本文介绍了ReferenceError:“Sheets”没有定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is my first attempt with script editor. I was assigned to do a script to crate pivot table for google sheet.

  //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:表格未定义。(第46行,文件代码)驳回

Please do check my code and explain where did i went wrong as every time im running the script editor error telling sheet is not defined popup. "ReferenceError: "Sheets" is not defined. (line 46, file "Code")Dismiss"

推荐答案

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

This an advanced service from google. You need to enable this service before using it. https://developers.google.com/apps-script/guides/services/advanced In the script editor, select Resources > Advanced Google services.... In the dialog that appears, click the on/off switch next to the service you want to use. At the bottom of the dialog, click the link for the Google API Console. In the console, click into the filter box and type part of the name of the API (for example, "Calendar"), then click the name once you see it. On the next screen, click Enable API. Close the API Console and return to the script editor. Click OK in the dialog. The advanced service you enabled is now available in autocomplete.

这篇关于ReferenceError:“Sheets”没有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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