亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

.length 不適用于 Google Apps 腳本中的數組

.length 不適用于 Google Apps 腳本中的數組

揚帆大魚 2023-03-03 15:59:09
我有這個代碼。我想遍歷數組并為每個條目創建一個新文檔。如果我手動將循環長度設置為它工作正常的行數。我想將它設置為循環數組的長度。但是,.length 屬性始終返回 null。我錯過了什么。我也嘗試過每個循環但沒有運氣。    function createDocument() {    //var headers = Sheets.Spreadsheets.Values.get('fileID', 'A1:Z1');  var studentHistory = Sheets.Spreadsheets.Values.get('fileID', 'A2:Z200');  var templateId = 'fileID';  var documentId;  var dstFolder = DriveApp.getFolderById('folderID');  var length = studentHistory.length;  Logger.log(studentHistory);  Logger.log(length);  //Loop through rows in sheet  for (var i = 0; i < length; i++){     //Get values from sheet row    var date = studentHistory.values[i][0];    var studentName = studentHistory.values[i][1];    var dob = studentHistory.values[i][2];    var pcDoctor = studentHistory.values[i][3];    var address = studentHistory.values[i][4];    var fgName = studentHistory.values[i][5];    var mgName = studentHistory.values[i][6];    var phoneMom = studentHistory.values[i][7];    var phoneDad = studentHistory.values[i][8];    var empMom = studentHistory.values[i][9];    var empDad = studentHistory.values[i][10];    var livesWith = studentHistory.values[i][11];    var childrenInHome = studentHistory.values[i][12];    var childrenNotInHome = studentHistory.values[i][13];    var othersInHome = studentHistory.values[i][14];    var illnesses = studentHistory.values[i][15];    var illnessDetails = studentHistory.values[i][16];    var hospitalizations = studentHistory.values[i][17];    var hospDetails = studentHistory.values[i][18];    var trauma = studentHistory.values[i][19];    var traumaDetails = studentHistory.values[i][20];    var injuries = studentHistory.values[i][21];    var injuryDetails = studentHistory.values[i][22];    var medications = studentHistory.values[i][23];    var additionalComments = studentHistory.values[i][24];    var otherSchools = studentHistory.values[i][25];  }}
查看完整描述

2 回答

?
明月笑刀無情

TA貢獻1828條經驗 獲得超4個贊

studentHistory.values是數組。

因此,試試這個來獲取長度:

var length = studentHistory.values.length;


查看完整回答
反對 回復 2023-03-03
?
呼如林

TA貢獻1798條經驗 獲得超3個贊

解決方案

我看到您正在使用 Advanced Google Services 調用 Sheets API。此 Apps 腳本類允許您直接從自動處理授權過程的腳本中調用 Google API。

但是,它不能作為內置類使用,例如在SpreadsheetApp包裝器中可用。

您的請求將按照以下規范返回類似 HTTP 的響應:

{

  "range": string,

  "majorDimension": enum (Dimension),

  "values": [

    array

  ]

}

您將需要解析這些響應以獲得所需的結果。


建議修改

    function createDocument() 

{

  

  //var headers = Sheets.Spreadsheets.Values.get('fileID', 'A1:Z1');

  var studentHistory = Sheets.Spreadsheets.Values.get('fileID', 'A2:Z200');

  var templateId = 'fileID';

  var documentId;

  var dstFolder = DriveApp.getFolderById('folderID');

  var length = studentHistory.values.length;


...


查看完整回答
反對 回復 2023-03-03
  • 2 回答
  • 0 關注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號