jpillora / node-edit-google-spreadsheet

A simple API for editing Google Spreadsheets
304 stars 101 forks source link

Can't read string values #19

Closed kjakub closed 10 years ago

kjakub commented 10 years ago

I am getting 0 instead of expected string from spreadsheet. What I am doing wrong?

Found rows: { '1': { '1': '1243', '2': '555', '3': 0 } } Info: { spreadsheetId: 'dsds', worksheetId: 'od6', worksheetTitle: 'Sheet1', worksheetUpdated: Wed Feb 12 2014 22:56:33 GMT+0700 (ICT), totalCells: 3, totalRows: 1, lastRow: 1, nextRow: 2 }

christiaanwesterbeek commented 10 years ago

@kjakub You're doing nothing wrong. @jpillora It's going wrong here in line 31 in lib/util.js

  //parse num value (if it's not a date)
  if(cell.numericValue && cell.numericValue === cell.inputValue || isNaN(Date.parse(cell.inputValue)))
    return exports.num(cell.numericValue); //<= line 31
  else //use string value
    return cell.inputValue;

Here's how the data from google spreadsheet looks like for a number and a string.

"gs$cell": {
    "row": "1",
    "col": "1",
    "inputValue": "123",
    "numericValue": "123.0",
    "$t": "123"
},
"gs$cell": {
    "row": "1",
    "col": "2",
    "inputValue": "qwerty",
    "$t": "qwerty"
}

For the string there's no numericValue, but isNaN(Date.parse("qwerty")) equals to true, then you do:

return exports.num(cell.numericValue);

but that should be:

return exports.num(cell.inputValue);
jpillora commented 10 years ago

Yep! Bug! PR anyone :)? Currently on vacation though I should be able to merge and republish

On Thursday, February 13, 2014, Christiaan Westerbeek < notifications@github.com> wrote:

@kjakub https://github.com/kjakub You're doing nothing wrong. @jpillorahttps://github.com/jpilloraIt's going wrong here in line 31 in lib/util.js

//parse num value (if it's not a date) if(cell.numericValue && cell.numericValue === cell.inputValue || isNaN(Date.parse(cell.inputValue))) return exports.num(cell.numericValue); //<= line 31 else //use string value return cell.inputValue;

Here's how the data from google spreadsheet looks like for a number and a string.

"gs$cell": { "row": "1", "col": "1", "inputValue": "123", "numericValue": "123.0", "$t": "123" }, "gs$cell": { "row": "1", "col": "2", "inputValue": "qwerty", "$t": "qwerty" }

For the string there's no numericValue, but isNaN(Date.parse("qwerty"))equals to true, then you do:

return exports.num(cell.numericValue);

but that should be:

return exports.num(cell.inputValue);

Reply to this email directly or view it on GitHubhttps://github.com/jpillora/node-edit-google-spreadsheet/issues/19#issuecomment-34917177 .

christiaanwesterbeek commented 10 years ago

Yeah I could but it's one word to change. Can't you do the commit using the editor on Github.com? It's easy.

Yep! Bug! PR anyone :)? Currently on vacation though I should be able to merge and republish

On Thursday, February 13, 2014, Christiaan Westerbeek < notifications@github.com> wrote:

@kjakub https://github.com/kjakub You're doing nothing wrong. @jpillorahttps://github.com/jpilloraIt's going wrong here in line 31 in lib/util.js

//parse num value (if it's not a date) if(cell.numericValue && cell.numericValue === cell.inputValue || isNaN(Date.parse(cell.inputValue))) return exports.num(cell.numericValue); //<= line 31 else //use string value return cell.inputValue;

Here's how the data from google spreadsheet looks like for a number and a string.

"gs$cell": { "row": "1", "col": "1", "inputValue": "123", "numericValue": "123.0", "$t": "123" }, "gs$cell": { "row": "1", "col": "2", "inputValue": "qwerty", "$t": "qwerty" }

For the string there's no numericValue, but isNaN(Date.parse("qwerty"))equals to true, then you do:

return exports.num(cell.numericValue);

but that should be:

return exports.num(cell.inputValue);

Reply to this email directly or view it on GitHub< https://github.com/jpillora/node-edit-google-spreadsheet/issues/19#issuecomment-34917177

.

Reply to this email directly or view it on GitHubhttps://github.com/jpillora/node-edit-google-spreadsheet/issues/19#issuecomment-34928374 .

derekjobst commented 10 years ago

Same issue here.