From 1b10a06205738da0960e6d48f79a3c77c03a2b05 Mon Sep 17 00:00:00 2001 From: David Bruant Date: Wed, 23 Oct 2024 21:06:01 +0200 Subject: [PATCH] Change XLSX imports to accodomate rollup bundles --- readme.md | 2 ++ scripts/createOdsFile.js | 15 ++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/readme.md b/readme.md index 8317e72..76b0b80 100644 --- a/readme.md +++ b/readme.md @@ -69,6 +69,8 @@ const ods = await createOdsFile(content) // 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 diff --git a/scripts/createOdsFile.js b/scripts/createOdsFile.js index ff10a0a..888b30b 100644 --- a/scripts/createOdsFile.js +++ b/scripts/createOdsFile.js @@ -1,12 +1,9 @@ //@ts-check -import XLSX from 'xlsx' - +import {write, utils} from 'xlsx' import {tableRawContentToValues} from './shared.js' -/** @import {SheetName, SheetRawContent, SheetRowRawContent, SheetCellRawContent} from './types.js' */ - -const officeVersion = '1.2' +/** @import {SheetName, SheetRawContent} from './types.js' */ /** * Crée un fichier .ods à partir d'un Map de feuilles de calcul @@ -14,14 +11,14 @@ const officeVersion = '1.2' * @returns {Promise} */ export async function createOdsFile(sheetsData) { - const workbook = XLSX.utils.book_new(); + const workbook = utils.book_new(); const sheetsDataValues = tableRawContentToValues(sheetsData) for(const [sheetName, table] of sheetsDataValues){ - const worksheet = XLSX.utils.aoa_to_sheet(table); - XLSX.utils.book_append_sheet(workbook, worksheet, sheetName); + const worksheet = utils.aoa_to_sheet(table); + utils.book_append_sheet(workbook, worksheet, sheetName); } - return XLSX.write(workbook, {bookType: 'ods', type: 'array'}); + return write(workbook, {bookType: 'ods', type: 'array'}); }