Working with ODS in TypeScript
OpenDocument Spreadsheet (ODS) file handling with sheet selection, advanced header processing, and high-performance data operations.
Installation
Section titled “Installation”npm install fairspecGetting Started
Section titled “Getting Started”ODS format is handled by the XLSX plugin, which provides:
loadXlsxTable- Load ODS files into tablessaveXlsxTable- Save tables to ODS filesXlsxPlugin- Plugin for framework integration
For example:
import { loadXlsxTable } from "fairspec"
const table = await loadXlsxTable({ data: "table.ods" })// the column types will be automatically inferredBasic Usage
Section titled “Basic Usage”Loading ODS Files
Section titled “Loading ODS Files”import { loadXlsxTable } from "fairspec"
// Load a simple ODS fileconst table = await loadXlsxTable({ data: "data.ods" })
// Load with custom format (specify sheet)const table = await loadXlsxTable({ data: "data.ods", format: { name: "ods", sheetName: "Sheet2" }})
// Load multiple ODS files (concatenated)const table = await loadXlsxTable({ data: ["part1.ods", "part2.ods", "part3.ods"]})Saving ODS Files
Section titled “Saving ODS Files”import { saveXlsxTable } from "fairspec"
// Save with default optionsawait saveXlsxTable(table, { path: "output.ods", format: { name: "ods" }})
// Save with custom sheet nameawait saveXlsxTable(table, { path: "output.ods", format: { name: "ods", sheetName: "Data" }})Advanced Features
Section titled “Advanced Features”Sheet Selection
Section titled “Sheet Selection”// Select by sheet number (1-indexed)const table = await loadXlsxTable({ data: "workbook.ods", format: { name: "ods", sheetNumber: 2 // Load second sheet }})
// Select by sheet nameconst table = await loadXlsxTable({ data: "workbook.ods", format: { name: "ods", sheetName: "Sales Data" }})Multi-Header Row Processing
Section titled “Multi-Header Row Processing”// ODS with multiple header rowsconst table = await loadXlsxTable({ data: "multi-header.ods", format: { name: "ods", headerRows: [1, 2], headerJoin: "_" }})// Resulting columns: ["Year_Quarter", "2023_Q1", "2023_Q2", "2024_Q1", "2024_Q2"]Comment Row Handling
Section titled “Comment Row Handling”// Skip specific comment rowsconst table = await loadXlsxTable({ data: "with-comments.ods", format: { name: "ods", commentRows: [1, 2], headerRows: [3] }})
// Skip rows with comment prefixconst table = await loadXlsxTable({ data: "data.ods", format: { name: "ods", commentPrefix: "#", headerRows: [1] }})Remote File Loading
Section titled “Remote File Loading”// Load from URLconst table = await loadXlsxTable({ data: "https://example.com/data.ods"})
// Load multiple remote filesconst table = await loadXlsxTable({ data: [ "https://api.example.com/data-2023.ods", "https://api.example.com/data-2024.ods" ]})Column Selection
Section titled “Column Selection”// Select specific columnsconst table = await loadXlsxTable({ data: "data.ods", format: { name: "ods", columnNames: ["name", "age", "city"] }})