Search code examples
javascriptgoogle-apps-scriptgoogle-sheetsformatgoogle-apps

How use a NumberFormat function on google apps script


I have a webapp that I get a value. I make an append row with this data for my sheet. However, I want that this data have a text format, because I want to get the value like I typed. Some problems happen with my sheet, like an "and" be recognized as a number. Ex: 2000e7 appears as: 2.00E + 10. I know that yhave a function to change the format. NumberFormat (" ")

But I think that I'm not using it correctly.

My code:

  var ws=  ss.getSheetByName(flag);
  ws.appendRow([Entrada,Modelo,SN,Ocorrencia,Status,data,obs])

  var ss2 = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss2.getSheets()[0];
  var range = sheet.getRange("My Last row");

// Money format
range.setNumberFormat("@");
  

Solution

  • Sometimes the better way is to prepend the value with ' rather than using setNumberFormat

    Related