Forum Discussion
dylanvan
Nov 07, 2025Copper Contributor
Script changing dates to text
I"m trying to make a script to transform a column with dates to text. Normally i would just use the TEXT function but the issue is that the new text values need to replace the old date values. The d...
Kidd_Ip
Nov 08, 2025MVP
Try this for replace dates with text:
- Inserts helper columns with TEXT() formulas.
- Converts them to plain text.
- Copies the values back to the original columns.
- Deletes the helper columns.
function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getActiveWorksheet();
let table = sheet.getTables()[0]; // Assumes there's only one table on the sheet
// Add helper columns to the table
table.addColumn(5, true).getRangeBetweenHeaderAndTotal().setFormulaLocal("=TEXT([@Geboortedatum],\"dd/mm/yyyy\")");
table.getColumn(5).getRange().setNumberFormatLocal("@");
table.addColumn(17, true).getRangeBetweenHeaderAndTotal().setFormulaLocal("=TEXT([@[Datum Resultaat]],\"dd/mm/yyyy\")");
table.getColumn(17).getRange().setNumberFormatLocal("@");
table.addColumn(19, true).getRangeBetweenHeaderAndTotal().setFormulaLocal("=TEXT([@Startdatum],\"dd/mm/yyyy\")");
table.getColumn(19).getRange().setNumberFormatLocal("@");
// Copy values from helper columns back to original columns
let rowCount = table.getRowCount();
for (let i = 0; i < rowCount; i++) {
let geboortedatumText = table.getColumn(5).getDataBodyRange().getCell(i, 0).getText();
let datumResultaatText = table.getColumn(17).getDataBodyRange().getCell(i, 0).getText();
let startdatumText = table.getColumn(19).getDataBodyRange().getCell(i, 0).getText();
table.getColumnByName("Geboortedatum").getDataBodyRange().getCell(i, 0).setValue(geboortedatumText);
table.getColumnByName("Datum Resultaat").getDataBodyRange().getCell(i, 0).setValue(datumResultaatText);
table.getColumnByName("Startdatum").getDataBodyRange().getCell(i, 0).setValue(startdatumText);
}
// Delete helper columns (assuming they were inserted at fixed positions)
table.getColumn(19).delete();
table.getColumn(17).delete();
table.getColumn(5).delete();
}
- dylanvanNov 10, 2025Copper Contributor
Thank you for the aid.
I tried your script but it gave problems with the execution. The script in the other reply worked perfectly so i'm using that one but i wanted to thank you for the aid anyway.