* Ajout de création de fichier .ods * Ajout d'un outil pour créer un fichier .ods + rajout de styles.xml et meta.xml pour peut-être plaire à LibreOffice * Créer des fichiers considérés corrompus-mais-réparables LibreOffice * Creating libre-office-validated ods files * readme with ods creation
28 lines
808 B
JavaScript
28 lines
808 B
JavaScript
//@ts-check
|
|
|
|
import XLSX from 'xlsx'
|
|
|
|
import {tableRawContentToValues} from './shared.js'
|
|
|
|
/** @import {SheetName, SheetRawContent, SheetRowRawContent, SheetCellRawContent} from './types.js' */
|
|
|
|
const officeVersion = '1.2'
|
|
|
|
/**
|
|
* 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) {
|
|
const workbook = XLSX.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);
|
|
}
|
|
|
|
return XLSX.write(workbook, {bookType: 'ods', type: 'array'});
|
|
}
|