Reputation: 295
This is related with this post. I'm trying to export data on separate worksheet. When I export the worksheet, it works, but it does not copy the date format.
This is the cell's output after running the script and exporting it.
function PrintMultiple() {
const srcSs = SpreadsheetApp.getActiveSpreadsheet();
const sheet = srcSs.getSheetByName("TEMPLATE");
const values = sheet.getRange("C2").getDataValidation().getCriteriaValues()[0].getValues().flat().filter(String);
const dstSs = SpreadsheetApp.create("SMRtempSpreadsheet");
SpreadsheetApp.getActive().toast("About to take some action... Please wait...");
values.forEach(v => {
sheet.getRange("C2").setValue(v);
SpreadsheetApp.flush();
const tempSheet = sheet.copyTo(srcSs);
const range = tempSheet.getDataRange();
range.copyTo(range, {contentsOnly: true});
tempSheet.getRange("B2:2").clear().clearDataValidations();
tempSheet.getDrawings().forEach(e => e.remove());
tempSheet.deleteColumn(1);
tempSheet.deleteRow(1);
tempSheet.deleteRow(2);
tempSheet.deleteRow(3);
tempSheet.copyTo(dstSs);
srcSs.deleteSheet(tempSheet);
});
dstSs.deleteSheet(dstSs.getSheets()[0]);
}
However, when I format the cell as DATE, it looks like this.
How can I export it as a DATE without manually formatting each one?
Upvotes: 2
Views: 737
Reputation: 295
SOLUTION THAT I USED:
var cell = tempSheet.getRange("D19");
cell.setNumberFormat('mm/dd/yyyy');
Upvotes: 3