为了账号安全,请及时绑定邮箱和手机立即绑定

类型错误:无法读取未定义的属性“值”(第 37 行,文件“代码”)

类型错误:无法读取未定义的属性“值”(第 37 行,文件“代码”)

慕侠2389804 2022-08-04 09:41:26
我创建了一个谷歌应用程序脚本,允许我从谷歌表格中创建一些谷歌文档模板。代码如下:function createDocument2 () {  var headers,i,L,scriptProps,tactics;  var endRowToRange,rangeForDate,sh,sheetTabName,ss,ssFileID,startRowToRange,templateId;   ssFileID = 'Google Sheet File ID';  templateId = 'Google Doc Template ID';  sheetTabName = "Google Sheet Tab Name";    ss = SpreadsheetApp.openById(ssFileID);  sh = ss.getSheetByName(sheetTabName);  endRowToRange = sh.getLastRow(); //The end row number will always be the last row in the sheet tab  Logger.log(endRowToRange);    scriptProps = PropertiesService.getScriptProperties();    startRowToRange = scriptProps.getProperty('startRow'); // Where the start row begins for this run of the code    /* endRowToRange = endRowToRange.toString(); //Needs to be a string to concatenate the A1 notation */    startRowToRange = startRowToRange.slice(0,startRowToRange.indexOf(".")); // Remove the decimal places FROM THE STRING  /* endRowToRange = endRowToRange.slice(0,endRowToRange.indexOf(".")); // Remove the decimal places */  Logger.log(endRowToRange);    if (!startRowToRange) {    startRowToRange = 2;  }    rangeForDate = 'A' + startRowToRange + ":I" + endRowToRange; // Build the A1 Notation for the data range  Logger.log('rangeForDate' + rangeForDate);    // Where we fill the Google Docs template    headers = sh.Spreadsheets.Values.get(ssFileID,'A1:I1');  tactics = sh.Spreadsheets.Values.get(ssFileID,rangeForDate);  L = tactics.values.length;  var i;    }    // Loop to retreive the values processed before    scriptProps.setProperty('startRow',endRowToRange + 1); // Save new start value}我已将此脚本复制到另一个文件夹,但它不再起作用,它说“TypeError:无法读取未定义的属性'值'(第37行,文件”代码“) - Google Apps Scrit”。当我从初始文件夹运行它时,它工作得很好。有人对这个问题有想法吗?
查看完整描述

1 回答

?
泛舟湖上清波郎朗

TA贡献1818条经验 获得超3个赞

因此,您需要进行一些更改。

startRowToRange = scriptProps.getProperty('startRow');

if(endRowToRange<startRowToRange) return;

将标题和策略更改为

headers = sh.getRange('A1:I1').getValues();
tactics = sh.getRange(rangeForDate).getValues();

价值观只使用战术


查看完整回答
反对 回复 2022-08-04
  • 1 回答
  • 0 关注
  • 111 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信