node-google-spreadsheet
node-google-spreadsheet copied to clipboard
How to check whether headers are present in the sheet or not ?
This im using to check headers await sheet.loadHeaderRow(1)
but giving error - Error: No values in the header row - fill the first row with header values before trying to interact with rows
Is there any way to check ?
Having the same issue. I thought something like this would work:
async function hasHeaders(sheet) {
try {
await sheet.loadHeaderRow()
return true;
} catch (error) {
return false;
}
}
But I guess it's not actually throwing an error because it seems it can't be caught.
that's nice hacky way.
is there no alternative way? I'd expect loadRows
to allow me to load the first row or even loadCells
to allow to load the first cell....
By default, loadRows
just automatically loads the header row for you, since in 90% of use cases, you are working with an existing sheet that already has the header set - or you've just set it on a new sheet and we already know what the headers are. In the case you need more control, that's sort of what sheet.loadHeaderRow
is for, but I can see it's a little awkward to have to throw / catch an untyped error.
We could add another option to the loadHeaderRow
method, or add another method which loads the headers without throwing... feel free to open a PR, or I'll try to add it in during my next pass of udpates.