“ReferenceError:”sheet“未定义。

时间:2016-05-05 17:43:26

标签: google-apps-script google-sheets

尝试运行代码时出现此错误。对于数据变量,它具体指向第71行。

function MAIN_createBatchMarketReports () { 
var marketReportDataSheet = getdataSheet(MARKET_REPORT_TEMPLATE_FILE_NAME); 
var currentDataColumn = INIT_DATA_COL;

var lastCol = marketReportDataSheet.getDataRange().getLastColumn();

var data = sheet.getRange(AGENT_NAME_ROW,currentDataColumn,1,lastCol).getValues()[0];

  for (var i = 0; i < data.length; i++) {

    if (data[i] != "" && data[i] != undefined) {
      createMarketReport(marketReportDataSheet, i+1);
    }

  }
}

完整脚本:http://pastebin.com/n70iLPsA

对正确方向的任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

我认为有一个错误,你必须将sheet替换为marketReportDataSheet。 变量表在函数getdataSheet中定义,而不是在MAIN_createBatchMarketReports函数中定义

function MAIN_createBatchMarketReports () { 
var marketReportDataSheet = getdataSheet(MARKET_REPORT_TEMPLATE_FILE_NAME); 
var currentDataColumn = INIT_DATA_COL;

var lastCol = marketReportDataSheet.getDataRange().getLastColumn();

var data = marketReportDataSheet.getRange(AGENT_NAME_ROW,currentDataColumn,1,lastCol).getValues()[0];

  for (var i = 0; i < data.length; i++) {

    if (data[i] != "" && data[i] != undefined) {
      createMarketReport(marketReportDataSheet, i+1);
    }

  }
}