Change XLSX imports to accodomate rollup bundles

This commit is contained in:
David Bruant 2024-10-23 21:06:01 +02:00
parent fae82b575e
commit 1b10a06205
2 changed files with 8 additions and 9 deletions

View File

@ -69,6 +69,8 @@ const ods = await createOdsFile(content)
// ods is an ArrayBuffer representing an ods file with the content described by the Map // ods is an ArrayBuffer representing an ods file with the content described by the Map
``` ```
(and there is a tool to test file creation:
`node tools/create-an-ods-file.js > yo.ods`)
#### Low-level #### Low-level

View File

@ -1,12 +1,9 @@
//@ts-check //@ts-check
import XLSX from 'xlsx' import {write, utils} from 'xlsx'
import {tableRawContentToValues} from './shared.js' import {tableRawContentToValues} from './shared.js'
/** @import {SheetName, SheetRawContent, SheetRowRawContent, SheetCellRawContent} from './types.js' */ /** @import {SheetName, SheetRawContent} from './types.js' */
const officeVersion = '1.2'
/** /**
* Crée un fichier .ods à partir d'un Map de feuilles de calcul * Crée un fichier .ods à partir d'un Map de feuilles de calcul
@ -14,14 +11,14 @@ const officeVersion = '1.2'
* @returns {Promise<ArrayBuffer>} * @returns {Promise<ArrayBuffer>}
*/ */
export async function createOdsFile(sheetsData) { export async function createOdsFile(sheetsData) {
const workbook = XLSX.utils.book_new(); const workbook = utils.book_new();
const sheetsDataValues = tableRawContentToValues(sheetsData) const sheetsDataValues = tableRawContentToValues(sheetsData)
for(const [sheetName, table] of sheetsDataValues){ for(const [sheetName, table] of sheetsDataValues){
const worksheet = XLSX.utils.aoa_to_sheet(table); const worksheet = utils.aoa_to_sheet(table);
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName); utils.book_append_sheet(workbook, worksheet, sheetName);
} }
return XLSX.write(workbook, {bookType: 'ods', type: 'array'}); return write(workbook, {bookType: 'ods', type: 'array'});
} }