There does not seem to be a way to use sheet.appendRow(data).set to append a row and use .setNumberFormat. No matter how I try it, the .setNumberFormat is not an option that pops up.
Here's what works for my situation, which might be helpful to others:
I am trying to append a row in which one of the cells has a serial number that starts with "000". The zeros are automatically removed if I don't put some text in the cell with it, unfortunately. Adding the text will be more work later. Here is the solution that works for me:
while (files.hasNext()) {
var file = files.next();
var name = file.getName(); // The name of the file is a serial number that starts with "000"
var url = file.getUrl();
var lastUpdate = file.getLastUpdated();
var description = file.getDescription();
var lastRow = sheet.getLastRow();
sheet.getRange(lastRow + 1, 1).setValue(name).setNumberFormat("@");
sheet.getRange(lastRow + 1, 2).setValue(url);
sheet.getRange(lastRow + 1, 3).setValue(lastUpdate);
sheet.getRange(lastRow + 1, 4).setValue(description);
}
It is not as simple as using sheet.appendRow(data).set, but it does append a row and sets the format to plain text. Hopefully, someone knows an easier way.
Here's more information from Google:
- setNumberFormats(numberFormats)
- About date and time values
range.setNumberFormat("@");
should set it to "plain text". – IntromissionRange.copyFormatToRange
to copy the formating from the source sheet. – Intromission