How do you add zero in front of number in google sheets

When I'm adding QRCODE number to Spreadsheet 0000000 are disappearing adding only 123... not 0000's
image


But we don't know for each row how many digit will be may be it'll 00 / 000/ 0000....
So how we can fix?
I tried this:


it's showing in row 000... but when I'm ADDing,
000's are disappering so how we can add Plain text on Block?

It is for you to decide....

What is the largest number you are likely to have ? 12 digits ?

In which case use 12 in the procedure, the correct number of 0's will be added in front of any number with less than 12 digits

123456789012
000000567890

These are no longer numbers but strings in your app, your column in the google sheet needs to be set for text, not a number. (google sheets may try to fight you over this!). Do not try to use number formatting on your column to add the zeros....

Here is my result:

RESULT:

ZEROs are disappering still ;((((
I guess I should change something on Spreadsheet settings ,

I think you should set that column as text instead of a number and see what happens.

QRcode column already in Plain text

What do the zeros further up in the menu do?

it has been added by manually not by click

I said google sheets would fight!

The fix (which I had forgotten!) is to add an apostrophe ' before the number with zeros, this will tell google sheets to treat it as a string.

You may need to use getDisplayValues instead of just getValues in other parts of your scripting, so that the apostrophe is not returned with your data

function doPost(e) { 
  var ss = SpreadsheetApp.openById(e.parameter.File);
  var sheet = ss.getSheetByName(e.parameter.Sheet);
 if (e.parameter.Action == "Edit_Truck") {
    var data = [("'" + e.parameter.qrCode),e.parameter.Item, e.parameter.Box];
    sheet.appendRow(data);
    return ContentService.createTextOutput([e.parameter.qrCode,e.parameter.Item, e.parameter.Box]);
  }
}

image

image

3 Likes

Yes, the same with excel sheet:

grafik

@TIMAI2 Thank you so much, it's working :+1:
Here is result:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.