My first experience with packages so don’t laugh.
I’ve installed google-spreadsheet and am using it like this:
import { GoogleSpreadsheet } from 'google-spreadsheet';
. . .
let doc = new GoogleSpreadsheet(<spreadsheet ID>);
doc.useServiceAccountAuth(<credentials>)
.then(() => {
doc.loadInfo();
})
.then(() => {
console.log(doc);
});
At this point, doc looks great. The console log shows a _rawSheets property that has all the correct sheets of my spreadsheet (two dozen or so); each sheet has the correct ID and title and so forth.
But nothing else works. At this point I want to say “var sheet = doc.sheetsByTitle[‘a title’]” to get a sheet object, but this throws an error. sheetsById and so forth don’t work either. These are defined as “get” properties in the source, and it’s as though Corvid’s JS doesn’t understand “get”.
And there’s more. Somehow I can’t get at the sheet objects even by hand. Though doc._rawSheets logs as an object with values indexed by numeric sheet ID, it doesn’t work to index into this object or to iterate over it or anything. That is, none of the following give me anything but null:
doc._rawSheets["<sheet id>"]
doc._rawSheets[<sheet id as a number>]
for (const key in doc._rawSheets) { ... }
Object.keys(doc._rawSheets)
_.forIn(doc._rawSheets, (a,b,c) => { ... })
Clearly I’m doing something hopelessly wrong. I’m new to JavaScript so maybe I’m handling objects incorrectly. Any help most gratefully appreciated.