forked from DustinBrett/daedalOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsheetjs.ts
More file actions
39 lines (31 loc) · 881 Bytes
/
sheetjs.ts
File metadata and controls
39 lines (31 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import type * as XLSX from "xlsx";
import { loadFiles } from "utils/functions";
declare global {
interface Window {
XLSX: typeof XLSX;
XLSX_ZAHL_PAYLOAD?: string;
}
}
const getSheetJs = async (): Promise<typeof XLSX> => {
if (!window.XLSX) {
await loadFiles(["/Program Files/SheetJS/xlsx.full.min.js"]);
}
return window.XLSX;
};
export const convertSheet = async (
fileData: Buffer,
extension: string
): Promise<Uint8Array> => {
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;
};