總的來說,我對編程很陌生,但對我迄今為止能夠為作業專案所做的事情感到興奮。我想知道為什么在下面的程式中,變數 companyID 沒有填充到模板文字字串中。我試過把它放在回圈內部和外部,雖然我沒有收到錯誤訊息,但它只是作為一個空格出現。
let activeSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('foreachloop');
let range = activeSheet.getRange(1, 1, 5, 4);
let values = range.getValues();
//FOR EACH LOOP
values.forEach(function(value, index){
let companyID = activeSheet.getRange(1, 9).getValue();
if (index ===0) return;
let descriptionVariable = `Employee Number ${companyID} ${value[0]} ${value[1]} has a current status of ${value[2]}`
activeSheet.getRange(index 1, 4).setValue(descriptionVariable);
})
}```
uj5u.com熱心網友回復:
試試這種方式:
function lfunko() {
const sh = SpreadsheetApp.getActive().getSheetByName('foreachloop');
const values = sh.getRange(1, 1, 5, 4).getValues();
const companyID = sh.getRange(1, 9).getValue();
values.forEach(function (value, index) {
if (index > 0) {
sh.getRange(index 1, 4).setValue(`Employee Number ${companyID} ${value[0]} ${value[1]} has a current status of ${value[2]}`);
}
});
}
uj5u.com熱心網友回復:
- 檢查您的運行時環境。如果要使用此功能,必須將其設定為 V8。請參閱https://developers.google.com/apps-script/guides/v8-runtime
- 檢查您從中提取的單元格的內容
companyID。是空的嗎?您可以console.log(companyID)或運行除錯器來檢查
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/466576.html
標籤:谷歌应用脚本
