diff --git a/client/src/pages/VentilationFreePro.tsx b/client/src/pages/VentilationFreePro.tsx index c5e2455..0c995ca 100644 --- a/client/src/pages/VentilationFreePro.tsx +++ b/client/src/pages/VentilationFreePro.tsx @@ -226,8 +226,8 @@ function VentilationFreeProContent() { // Gestion du fichier const handleFile = useCallback( (file: File) => { - if (!file.name.match(/\.(xlsx|xls)$/i)) { - toast.error("Format invalide : veuillez sélectionner un fichier Excel (.xlsx ou .xls)"); + if (!file.name.match(/\.(xlsx|xls|csv)$/i)) { + toast.error("Format invalide : veuillez sélectionner un fichier Excel (.xlsx, .xls) ou CSV (.csv)"); return; } const reader = new FileReader(); @@ -305,7 +305,7 @@ function VentilationFreeProContent() { { const f = e.target.files?.[0]; if (f) handleFile(f); }} /> @@ -320,7 +320,7 @@ function VentilationFreeProContent() {
Glissez-déposez le fichier Excel FreePro ici
-ou cliquez pour sélectionner (.xlsx, .xls)
+ou cliquez pour sélectionner (.xlsx, .xls, .csv)
)} diff --git a/server/freeproService.ts b/server/freeproService.ts index ca9a52c..9de73b1 100644 --- a/server/freeproService.ts +++ b/server/freeproService.ts @@ -77,9 +77,16 @@ function getType(labelClient: string, script: string): string { */ export function processFreeproExcel( buffer: Buffer, - moisLabel: string + moisLabel: string, + fileName?: string ): FreeproVentilationResult { - const wb = xlsx.read(buffer, { type: "buffer", cellDates: true }); + // Détecter si c'est un CSV (par extension ou par détection du contenu) + const isCsv = fileName + ? /\.csv$/i.test(fileName) + : !buffer[0] || (buffer[0] !== 0x50 && buffer[0] !== 0xD0); // PK = xlsx, D0CF = xls + const wb = isCsv + ? xlsx.read(buffer.toString("utf8"), { type: "string", cellDates: true }) + : xlsx.read(buffer, { type: "buffer", cellDates: true }); const ws = wb.Sheets[wb.SheetNames[0]]; const rawRows = xlsx.utils.sheet_to_json