import { loadFiles } from "utils/functions"; import type * as XLSX from "xlsx"; declare global { interface Window { XLSX: typeof XLSX; XLSX_ZAHL_PAYLOAD?: string; } } const getSheetJs = async (): Promise => { if (!window.XLSX) { await loadFiles(["/Program Files/SheetJS/xlsx.full.min.js"]); } return window.XLSX; }; export const convertSheet = async ( fileData: Buffer, extension: string ): Promise => { const sheetJs = await getSheetJs(); let numbers: string | undefined; if (extension === "numbers") { await loadFiles(["/Program Files/SheetJS/xlsx.zahl.js"]); if (!window.XLSX_ZAHL_PAYLOAD) return Buffer.from(""); numbers = window.XLSX_ZAHL_PAYLOAD; } return sheetJs.write(sheetJs.read(fileData), { bookType: extension as XLSX.BookType, numbers, type: "buffer", }) as Uint8Array; };