theoephraim / node-google-spreadsheet

Google Sheets API wrapper for Javascript / Typescript
https://theoephraim.github.io/node-google-spreadsheet
The Unlicense
2.31k stars 391 forks source link

Cannot properly read some empty cells #286

Closed ERT-Kim closed 4 years ago

ERT-Kim commented 4 years ago

When trying to read some empty cells like this, following error occurs:

async function foo(sheet){
    await sheet.loadCells();
    let value = sheet.getCell(1,1).value; // here occurs error
    // some code
}

TypeError: Cannot read property 'effectiveValue' of undefined at GoogleSpreadsheetCell.get value [as value] (/app/node_modules/google-spreadsheet/lib/GoogleSpreadsheetCell.js:38:24)

One weird thing is that, for the similar code which accesses the other worksheet of same document, the value of empty cells is null and the code works fine. Maybe there is a problem getting CellData of empty cells...

theoephraim commented 4 years ago

Ah I think I know what's going on. It has to do with fetching all cells (ie no filter) in an empty sheet. In the meantime

ERT-Kim commented 4 years ago

Work well with the 2nd solution. Thanks.

theoephraim commented 4 years ago

I'm trying to recreate this so I can fix it, but am having trouble. Was there anything special about the sheet that you were reading from? Maybe you can share it (or a copy of it) with me - theozero@gmail.com

ERT-Kim commented 4 years ago

OK, I just invited you to share the copy of the sheet.

vogre commented 4 years ago

For me it's calling loadCells twice for empty cells causes a TypeError on access

When cell is initialized with constructor default cellData is an empty {}, but when updated it's undefined in: https://github.com/theoephraim/node-google-spreadsheet/blob/786be59c75f34c9deae0b184885173c6812583ad/lib/GoogleSpreadsheetWorksheet.js#L78

theoephraim commented 4 years ago

thanks @vogre! I'll take a look

theoephraim commented 4 years ago

deploying this fix shortly. Thanks folks!