Apps Script 的新手,关于为什么变量没有显示的问题
Very New to Apps Script, question about why variable isn't showing up
总的来说,我对编程还很陌生,但对我迄今为止能够为工作项目所做的一切感到兴奋。我想知道为什么在下面的程序中,变量 companyID 没有填充到模板文字字符串中。我试过将它放在循环内部和外部,虽然我没有收到错误消息,但它只是以 space.
的形式出现
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);
})
}```
- 检查您的运行时间环境。如果要使用此功能,必须将其设置为 V8。参见 https://developers.google.com/apps-script/guides/v8-runtime
- 检查您要从中提取
companyID
的单元格的内容。它是空的吗?您可以 console.log(companyID)
或 运行 一个调试器来检查
这样试试:
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]}`);
}
});
}
总的来说,我对编程还很陌生,但对我迄今为止能够为工作项目所做的一切感到兴奋。我想知道为什么在下面的程序中,变量 companyID 没有填充到模板文字字符串中。我试过将它放在循环内部和外部,虽然我没有收到错误消息,但它只是以 space.
的形式出现 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);
})
}```
- 检查您的运行时间环境。如果要使用此功能,必须将其设置为 V8。参见 https://developers.google.com/apps-script/guides/v8-runtime
- 检查您要从中提取
companyID
的单元格的内容。它是空的吗?您可以console.log(companyID)
或 运行 一个调试器来检查
这样试试:
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]}`);
}
});
}