2024-06-15 12:54:53 +02:00
|
|
|
//@ts-check
|
|
|
|
|
|
2025-03-25 22:06:53 +01:00
|
|
|
import {DOMParser, DOMImplementation, XMLSerializer} from '@xmldom/xmldom'
|
2024-06-15 12:54:53 +02:00
|
|
|
|
2024-06-18 11:06:41 +02:00
|
|
|
import {
|
|
|
|
|
_getODSTableRawContent,
|
|
|
|
|
_getXLSXTableRawContent
|
|
|
|
|
} from './shared.js'
|
2025-03-25 22:06:53 +01:00
|
|
|
import { _createOdsFile } from './createOdsFile.js'
|
|
|
|
|
|
|
|
|
|
/** @import {SheetCellRawContent, SheetName, SheetRawContent} from './types.js' */
|
2024-06-15 12:54:53 +02:00
|
|
|
|
2024-10-23 19:13:29 +02:00
|
|
|
|
|
|
|
|
function parseXML(str){
|
|
|
|
|
return (new DOMParser()).parseFromString(str, 'application/xml');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-06-15 12:54:53 +02:00
|
|
|
/**
|
2024-06-18 11:06:41 +02:00
|
|
|
* @param {ArrayBuffer} odsArrBuff
|
|
|
|
|
* @returns {ReturnType<_getODSTableRawContent>}
|
2024-06-15 12:54:53 +02:00
|
|
|
*/
|
2024-06-18 11:06:41 +02:00
|
|
|
export function getODSTableRawContent(odsArrBuff){
|
|
|
|
|
return _getODSTableRawContent(odsArrBuff, parseXML)
|
2024-06-15 12:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
2024-06-15 16:29:16 +02:00
|
|
|
/**
|
2024-06-18 11:06:41 +02:00
|
|
|
* @param {ArrayBuffer} xlsxArrBuff
|
|
|
|
|
* @returns {ReturnType<_getXLSXTableRawContent>}
|
2024-06-15 16:29:16 +02:00
|
|
|
*/
|
2024-06-18 11:06:41 +02:00
|
|
|
export function getXLSXTableRawContent(xlsxArrBuff){
|
|
|
|
|
return _getXLSXTableRawContent(xlsxArrBuff, parseXML)
|
2024-06-15 16:29:16 +02:00
|
|
|
}
|
|
|
|
|
|
2025-03-25 22:06:53 +01:00
|
|
|
const implementation = new DOMImplementation()
|
|
|
|
|
|
|
|
|
|
/** @type { typeof DOMImplementation.prototype.createDocument } */
|
|
|
|
|
const createDocument = function createDocument(...args){
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
return implementation.createDocument(...args)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const serializer = new XMLSerializer()
|
|
|
|
|
|
|
|
|
|
/** @type { typeof XMLSerializer.prototype.serializeToString } */
|
|
|
|
|
const serializeToString = function serializeToString(node){
|
|
|
|
|
return serializer.serializeToString(node)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {Map<SheetName, SheetRawContent>} sheetsData
|
|
|
|
|
*/
|
|
|
|
|
export function createOdsFile(sheetsData){
|
|
|
|
|
return _createOdsFile(sheetsData, createDocument, serializeToString)
|
|
|
|
|
}
|
2024-06-16 13:57:12 +02:00
|
|
|
|
2024-06-18 11:06:41 +02:00
|
|
|
export {
|
|
|
|
|
// table-level exports
|
|
|
|
|
tableWithoutEmptyRows,
|
|
|
|
|
tableRawContentToValues,
|
|
|
|
|
tableRawContentToStrings,
|
|
|
|
|
tableRawContentToObjects,
|
2024-06-18 11:49:57 +02:00
|
|
|
|
|
|
|
|
// sheet-level exports
|
|
|
|
|
sheetRawContentToObjects,
|
|
|
|
|
sheetRawContentToStrings,
|
|
|
|
|
|
|
|
|
|
// row-level exports
|
|
|
|
|
rowRawContentToStrings,
|
|
|
|
|
isRowNotEmpty,
|
|
|
|
|
|
|
|
|
|
// cell-level exports
|
|
|
|
|
cellRawContentToStrings,
|
|
|
|
|
convertCellValue
|
2024-06-18 11:06:41 +02:00
|
|
|
} from './shared.js'
|
2024-06-15 16:29:16 +02:00
|
|
|
|