exports.find_last_index = function(){
doc.useServiceAccountAuth(creds, function(err){
doc.getCells(
1 // index of sheet
, {
"min-row" : 1
, "min-col" : 1
, "max-row" : 1600
, "max-col" : 1
, "return-empty" : true
}
, function(err, cells) {
var last;
if(err) console.log(err);
// console.log(cells);
for(var num = 0; 1600 > num; num++) {
if(cells[num].value == ""){
last = num-1;
break;
}
}
console.log("-------------------");
console.log(last);
index = last; //index is global variable
return last;
}
);
});
return index; //<--- It returns null
}
此函数可通过googlespreadsheet npm从Google电子表格
获取最后一行索引
但是由于延迟从Google服务器获取工作表数据,因此find_last_index返回null。.
如何控制呢?