diff --git a/src/importer/features/main/index.tsx b/src/importer/features/main/index.tsx index c2a8351f..8222dd69 100644 --- a/src/importer/features/main/index.tsx +++ b/src/importer/features/main/index.tsx @@ -152,7 +152,20 @@ export default function Main(props: CSVImporterProps) { break; case "xlsx": case "xls": - const workbook = XLSX.read(bstr as string, { type: "binary" }); + const workbook = XLSX.read(bstr as string, { type: "binary", cellDates: true }); + for (const sheetName of workbook.SheetNames) { + const sheet = workbook.Sheets[sheetName]; + for (const [cellRef, cell] of Object.entries(sheet)) { + // skip metadata + if (cellRef.startsWith("!")) continue; + + // only process date cells + if (cell.t !== "d") continue; + + // Force format into YYYY-MM-DD + cell.v = XLSX.SSF.format("yyyy-mm-dd", cell.v); + } + } const sheetList = workbook.SheetNames; const data = XLSX.utils.sheet_to_json(workbook.Sheets[sheetList[0]], { header: 1 }) as Array>; const rows: FileRow[] = data.filter(isNotBlankRow).map((row: string[], index: number) => ({ index, values: row }));