我需要使index_to_write变量在函数外部可见。我怎样才能使这成为可能?
const XlsxPopulate = require('xlsx-populate');
let found = false;
let i = 1;
let index_to_write = 0;
XlsxPopulate.fromFileAsync("todo-list.xlsx")
.then(workBook => {
while (i <= 10 && found === false){
const value = workBook.sheet("Do-Shopping").cell("A" + i.toString()).value();
if (value === undefined) {
found = true;
index_to_write = i.toString();
}
i++;
}
});
console.log("A " + index_to_write + " is the first one to be free of data");
我尝试return index_to_write;在下面添加index_to_write = i.toString();但它不能解决问题。
目前,它显示0,与初始化时一样,但它应该打印4。如何修复它?
非常感谢您!
慕莱坞森
相关分类