我正在使用‘google-电子表格’,我正在成功地创建一个新的工作表,但由于某些原因,我无法操作甚至选择它。我搜索了所有的文档和网站,但仍然找不到解决办法。
async function startup () {
const doc = new GoogleSpreadsheet(config.sheetID);
let creds = require('login data')
await doc.useServiceAccountAuth(creds);
await doc.loadInfo(); // loads document properties and worksheets
console.log(doc.title);
for (var i = 0; i < config.channelID.length; i++) {
doc.addSheet({ title: config.channelID[i] })
let sheet = await doc.sheetsByTitle(config.channelID[i])
}
}
(node:50552) UnhandledPromiseRejectionWarning: TypeError: doc.sheetsByTitle is not a function
发布于 2020-11-04 08:36:25
当我看到“节点-谷歌-电子表格”的脚本时,doc.sheetsByTitle
似乎返回了一个对象。参考我想这可能是你出问题的原因。那么下面的修改如何?
发自:
for (var i = 0; i < config.channelID.length; i++) {
doc.addSheet({ title: config.channelID[i] })
let sheet = await doc.sheetsByTitle(config.channelID[i])
}
至:
for (var i = 0; i < config.channelID.length; i++) {
await doc.addSheet({ title: config.channelID[i] });
let sheet = doc.sheetsByTitle[config.channelID[i]];
console.log(sheet.title); // You can check the added sheet name here.
}
或者,在您的示例中,doc.addSheet
还返回sheet对象。所以您可以使用以下脚本。
for (var i = 0; i < config.channelID.length; i++) {
const addedSheet = await doc.addSheet({ title: config.channelID[i] });
console.log(addedSheet.title); // You can check the added sheet name here.
}
注意:
await
到doc.addSheet
。google-spreadsheet@3.0.13
。参考资料:
https://stackoverflow.com/questions/64674846
复制相似问题