2024-10-23 19:13:29 +02:00
|
|
|
//@ts-check
|
|
|
|
|
|
2024-10-23 21:06:01 +02:00
|
|
|
import {write, utils} from 'xlsx'
|
2024-10-23 19:13:29 +02:00
|
|
|
import {tableRawContentToValues} from './shared.js'
|
|
|
|
|
|
2024-10-23 21:06:01 +02:00
|
|
|
/** @import {SheetName, SheetRawContent} from './types.js' */
|
2024-10-23 19:13:29 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Crée un fichier .ods à partir d'un Map de feuilles de calcul
|
|
|
|
|
* @param {Map<SheetName, SheetRawContent>} sheetsData
|
|
|
|
|
* @returns {Promise<ArrayBuffer>}
|
|
|
|
|
*/
|
|
|
|
|
export async function createOdsFile(sheetsData) {
|
2024-10-23 21:06:01 +02:00
|
|
|
const workbook = utils.book_new();
|
2024-10-23 19:13:29 +02:00
|
|
|
|
|
|
|
|
const sheetsDataValues = tableRawContentToValues(sheetsData)
|
|
|
|
|
|
|
|
|
|
for(const [sheetName, table] of sheetsDataValues){
|
2024-10-23 21:06:01 +02:00
|
|
|
const worksheet = utils.aoa_to_sheet(table);
|
|
|
|
|
utils.book_append_sheet(workbook, worksheet, sheetName);
|
2024-10-23 19:13:29 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-23 21:06:01 +02:00
|
|
|
return write(workbook, {bookType: 'ods', type: 'array'});
|
2024-10-23 19:13:29 +02:00
|
|
|
}
|