首页 > 解决方案 > 无法让 node-google-spreadsheet 在 Corvid Wix 中工作

问题描述

我正在尝试使用该node-google-spreadsheet软件包(平台 Wix 和 Corvid),因此:

import { GoogleSpreadsheet } from 'google-spreadsheet'; 

function handleSpreadsheet(request) {
    let doc = new GoogleSpreadsheet(<spreadsheet ID>); 
    doc.useServiceAccountAuth(<credentials>)
       .then(() => {
           doc.loadInfo();
       })
       .then(() => {
           // Logging Point
           var sheet = doc.sheetsByTitle['May 1'];
       });  

到 Logging Point 为止,一切似乎都运行正常。如果我在那里执行“console.log(doc)”,则表明 doc 具有一个_rawSheets属性,该属性包含我的电子表格的所有正确工作表(两打左右);每张纸都有正确的 ID 和标题等。也就是说,它肯定至少从 Google 表格中加载了那么多数据。

但是对 doc.sheetsByTitle 的引用(这是下一步,获取工作表对象)会引发错误,我不知道为什么。其他工作表访问函数,例如 sheetById,也会引发错误。这些在源代码中被定义为“get”属性,就好像 Corvid 的 JS 不理解“get”一样。

绝望中我试图直接接近这些物体,但我不明白的东西阻止了我。以下是 console.log 输出的一些示例,均取自上面的 Logging Point:

console.log(doc._rawSheets)       ==> { 0: {...}, 106791250: {...}, ...}
console.log(doc._rawSheets["0"])  ==> null
console.log(doc._rawSheets[0])    ==> null
console.log(Object.keys(doc._rawSheets)) ==> Array(0)
console.log(doc.sheetsByTitle)    ==> null

科维德的特性?用户PEBKAC?非常感谢您对尝试的事情提出建议。

作为记录,node-google-spreadsheet 包的文档在这里

标签: node.jsgoogle-sheetsgoogle-sheets-apivelo

解决方案


推荐阅读