Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ReferenceError:“引用错误”;“工作表”;没有定义_Javascript_Json_Google Sheets - Fatal编程技术网

Javascript ReferenceError:“引用错误”;“工作表”;没有定义

Javascript ReferenceError:“引用错误”;“工作表”;没有定义,javascript,json,google-sheets,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 co

这是我第一次尝试使用脚本编辑器。我被指派做一个脚本来为谷歌工作表包装数据透视表

  //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行,文件“代码”)驳回“

这是谷歌提供的高级服务。您需要先启用此服务,然后才能使用它。 在脚本编辑器中,选择资源>高级谷歌服务。。。。 在出现的对话框中,单击要使用的服务旁边的开/关开关。 在对话框底部,单击GoogleAPI控制台的链接。 在控制台中,单击筛选框并键入API名称的一部分(例如,“日历”),然后在看到该名称后单击该名称。 在下一个屏幕上,单击启用API。
关闭API控制台并返回脚本编辑器。在对话框中单击“确定”。您启用的高级服务现在可以在autocomplete中使用。

只需从这里添加所需的服务,您需要的是Google Sheets API。祝你好运


剂量表来自哪里?是全局Obj,然后检查它是否存在并已加载。你可以通过控制台确认它,我们需要启用什么服务?你需要启用
googlesheetsapi
服务