function main(workbook: ExcelScript.Workbook): string {
const table = workbook.getWorksheet(« RA_4357 »).getTables()[0];
const tableHeaders = table.getHeaderRowRange().getValues()[0] as string[];
const dataValues = table.getRangeBetweenHeaderAndTotal().getValues();
// Colonnes à convertir en date ISO (ajoutez/retirez selon vos besoins)
const dateColumns = [
« GO production date »,
« CJB delivery date confirmed »,
« Agreed Delivery Date »,
« Date Reengagement Anticipation »,
« Date Reengagement Retard »,
« DATE FINALE »
];
// Convertit « JJ/MM/AAAA » -> « AAAA-MM-JJ » ; laisse vide si vide
function toISO(value: string): string {
if (!value || value.trim() === « ») return « »;
const parts = value.split(« / »);
if (parts.length !== 3) return « »; // format inattendu -> vide, pas d’erreur
const [jj, mm, aaaa] = parts;
return `${aaaa}-${mm.padStart(2, « 0 »)}-${jj.padStart(2, « 0 »)}`;
}
let jsonArray: object[] = [];
for (let i = 0; i < dataValues.length; i++) {
let jsonObject: { [key: string]: string } = {};
for (let j = 0; j < dataValues[i].length; j++) {
const header = tableHeaders[j] as string;
let cell = dataValues[i][j] as string;
if (dateColumns.indexOf(header) !== -1) {
cell = toISO(cell); // conversion pour les colonnes de dates
}
jsonObject[header] = cell;
}
jsonArray.push(jsonObject);
}
return JSON.stringify(jsonArray);
}

