theoephraim / node-google-spreadsheet

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

Wierd ' added to numerical text. #696

Closed crackedpotato007 closed 4 months ago

crackedpotato007 commented 4 months ago

I am inputting values to 3 different cells.

2 of which have a numbered input, i.e ticket number(4 digit number) and no of customers served(Decimal/Integer)

If for example the ticket number is 1928, the spreadsheet ends up saying " '1928 ", notice the extra ', same goes for number of person served 1 ends up as '1 and 1.00 ends up as '1.00

Interestingly the third field, which is the name of representative which takes in a string, eg Jake doesn't have this mysterious ' added to it.


//pers=1, ticket=1928, name=Jake
await doc.loadInfo(); // loads document properties and worksheets
  const sheet = doc.sheetsByIndex[0];
  const rows = await sheet.getRows();
  const lastrow = rows.length + 1;
  await sheet.loadCells("A1:C5000");

  const ticketCell = sheet.getCellByA1(`A${lastrow + 1}`);
  const nameCell = sheet.getCellByA1(`B${lastrow + 1}`);
  const persCell = sheet.getCellByA1(`C${lastrow + 1}`);
  ticketCell.value = ticket;
  nameCell.value = name;
  persCell.value = pers;
  await sheet.saveUpdatedCells();
theoephraim commented 4 months ago

That extra ' tells google sheets to treat the value as text.

For example in the sheets UI, if you type 0001 into a cell, you'll see it coerces it to a number 1, but if you type '0001 it will keep the leading zeros and treat it as a string.

When you set the value, use an actual number (run parseInt on it first) then it should treat it and save it as you expect.

crackedpotato007 commented 4 months ago

Yep that was it.

Didn't know about this functionality on sheets. Much appreciated.