r/GoogleAppsScript • u/True_Teacher_9528 • Aug 19 '25
Question Leading and trailing zeros being dropped when CSV file is created
Hey all,
I have what should be a pretty straightforward problem, but can't for the life of me figure out why it's happening and how to fix it. Here is the relevant snippet of the code in question:
let csvString = '';
for(let row of bookTransArr) {
row.pop();
csvString += row.join() + '\n';
}
Logger.log(bookTransArr);
Logger.log(csvString);
let newCSVFile = DriveApp.createFile('tempBankTransfer.csv', csvString, MimeType.CSV);
Browser.msgBox(`Here is the link to the folder housing the temp CSV file for the US Bank bank transfer import: ${newCSVFile.getUrl()}`);This code is meant to take a 2D array (bookTransArr) and convert it to a CSV file for an import down the road. The problem is, in two of the columns, one being amounts and the other being dates, it is automatically getting rid of any trailing and leading zeros, which I need to mirror the requirements of the import. I have already confirmed when the CSV string is being constructed, it does not get rid of the zeros just by logging the string after it's construction. I'm almost positive it's getting rid of the zeros at the "DriveApp.createFile" step, but don't really know how to stop it from doing so. Any help with this is greatly appreciated!




