0
因此,我正在從電子表格中獲取數據,將相關部分放入數組中並將其寫回新的電子表格。數據來自谷歌形式,並不是每個人都有對每個問題的輸入,所以我只接受非空的問題。這導致我的數組的長度變化谷歌腳本insertSheet不接受字符串對象?
所以我已經把它放到了最親密的步驟,我被卡在插入工作表的部分,它在1的迭代中工作正常,但是當我在循環中執行它是有錯誤的。
for (j=2; j <= 3 ; j++)// I have 23 iterations, but I stopped at 2 for now
{
var cellLocation = new String ("B" + j + ":AC" + j);
Logger.log("J is " + j + "Cell location " + cellLocation);
var workingRange = buySheet.getRange(cellLocation);
var customer = workingRange.getValues(); //this produces a range of the row
Logger.log("Range is " + workingRange.getA1Notation() + " data is " + customer[0][0]);
//At first I thought it was the range- so I broke everything out into the tiniest step
var nameCustomer = new String(customer[0][0]);
Logger.log("nameCustomer is " + nameCustomer);
//this correctly prints out the names as strings- through 23 iterations
var create = buySheet.insertSheet(nameCustomer);
//this is a sheet object with the customers name- fails after the first iteration, and creates sheets with blank names -
}
這是我使用的參考:https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#insertSheet(String)
我註釋掉了一切後,這對解決這一棘手的問題。我試過在循環外實例化字符串。我可以發佈日誌,我使用的是真實數據,所以我不得不模糊人的名字。
它適用於第一輪,它工作,如果我手動鍵入一個字符串。