odf-kit 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +155 -13
  2. package/package.json +5 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # odf-kit
2
2
 
3
- Generate, fill, read, and convert OpenDocument Format files (.odt) in TypeScript and JavaScript. Works in Node.js and browsers. No LibreOffice dependency — pure spec-compliant ODF.
3
+ Generate, fill, read, and convert OpenDocument Format files (.odt, .ods) in TypeScript and JavaScript. Works in Node.js and browsers. No LibreOffice dependency — pure spec-compliant ODF.
4
4
 
5
5
  **[Documentation & examples →](https://githubnewbie0.github.io/odf-kit/)**
6
6
 
@@ -8,10 +8,10 @@ Generate, fill, read, and convert OpenDocument Format files (.odt) in TypeScript
8
8
  npm install odf-kit
9
9
  ```
10
10
 
11
- ## Four ways to work with ODT files
11
+ ## Five ways to work with ODF files
12
12
 
13
13
  ```typescript
14
- // 1. Build a document from scratch
14
+ // 1. Build an ODT document from scratch
15
15
  import { OdtDocument } from "odf-kit";
16
16
 
17
17
  const doc = new OdtDocument();
@@ -26,7 +26,22 @@ const bytes = await doc.save();
26
26
  ```
27
27
 
28
28
  ```typescript
29
- // 2. Fill an existing .odt template with data
29
+ // 2. Build an ODS spreadsheet from scratch
30
+ import { OdsDocument } from "odf-kit";
31
+
32
+ const doc = new OdsDocument();
33
+ const sheet = doc.addSheet("Sales");
34
+ sheet.addRow(["Month", "Revenue", "Growth"], { bold: true, backgroundColor: "#DDDDDD" });
35
+ sheet.addRow(["January", 12500, 0.08]);
36
+ sheet.addRow(["February", 14200, 0.136]);
37
+ sheet.addRow(["Total", { value: "=SUM(B2:B3)", type: "formula" }]);
38
+ sheet.setColumnWidth(0, "4cm");
39
+ sheet.setColumnWidth(1, "4cm");
40
+ const bytes = await doc.save();
41
+ ```
42
+
43
+ ```typescript
44
+ // 3. Fill an existing .odt template with data
30
45
  import { fillTemplate } from "odf-kit";
31
46
 
32
47
  const template = readFileSync("invoice-template.odt");
@@ -44,7 +59,7 @@ writeFileSync("invoice.odt", result);
44
59
  ```
45
60
 
46
61
  ```typescript
47
- // 3. Read an existing .odt file
62
+ // 4. Read an existing .odt file
48
63
  import { readOdt, odtToHtml } from "odf-kit/reader";
49
64
 
50
65
  const bytes = readFileSync("report.odt");
@@ -53,7 +68,7 @@ const html = odtToHtml(bytes); // styled HTML string
53
68
  ```
54
69
 
55
70
  ```typescript
56
- // 4. Convert .odt to Typst for PDF generation
71
+ // 5. Convert .odt to Typst for PDF generation
57
72
  import { odtToTypst } from "odf-kit/typst";
58
73
  import { execSync } from "child_process";
59
74
 
@@ -70,12 +85,12 @@ execSync("typst compile letter.typ letter.pdf");
70
85
  npm install odf-kit
71
86
  ```
72
87
 
73
- Node.js 22+ required. ESM only. Three sub-exports:
88
+ Node.js 22+ required. ESM only. Sub-exports:
74
89
 
75
90
  ```typescript
76
- import { OdtDocument, fillTemplate } from "odf-kit"; // build + fill
77
- import { readOdt, odtToHtml } from "odf-kit/reader"; // read + convert to HTML
78
- import { odtToTypst, modelToTypst } from "odf-kit/typst"; // convert to Typst
91
+ import { OdtDocument, OdsDocument, fillTemplate } from "odf-kit"; // build + fill
92
+ import { readOdt, odtToHtml } from "odf-kit/reader"; // read + HTML
93
+ import { odtToTypst, modelToTypst } from "odf-kit/typst"; // Typst/PDF
79
94
  ```
80
95
 
81
96
  Works in Node.js, browsers, Deno, Bun, and Cloudflare Workers. The only runtime dependency is [fflate](https://github.com/101arrowz/fflate) for ZIP packaging — no transitive dependencies.
@@ -107,7 +122,7 @@ Template filling and reading work the same way — pass `Uint8Array` bytes from
107
122
 
108
123
  ---
109
124
 
110
- ## Build: programmatic document creation
125
+ ## Build: ODT documents
111
126
 
112
127
  ### Text and formatting
113
128
 
@@ -271,6 +286,94 @@ const bytes = await new OdtDocument()
271
286
 
272
287
  ---
273
288
 
289
+ ## Build: ODS spreadsheets
290
+
291
+ `OdsDocument` generates `.ods` spreadsheet files with multiple sheets, typed cells, formatting, and formulas.
292
+
293
+ ### Cell types
294
+
295
+ Values are auto-typed from their JavaScript type. Use an explicit `OdsCellObject` when you need formulas or per-cell overrides.
296
+
297
+ ```typescript
298
+ import { OdsDocument } from "odf-kit";
299
+
300
+ const doc = new OdsDocument();
301
+ const sheet = doc.addSheet("Data");
302
+
303
+ sheet.addRow([
304
+ "Text", // string
305
+ 42, // float
306
+ new Date("2026-01-15"), // date
307
+ true, // boolean
308
+ null, // empty cell
309
+ { value: "=SUM(B1:B10)", type: "formula" }, // formula — explicit required
310
+ ]);
311
+ ```
312
+
313
+ ### Row and cell formatting
314
+
315
+ Options on `addRow()` apply to all cells in the row. Per-cell options inside an `OdsCellObject` override the row defaults.
316
+
317
+ ```typescript
318
+ // Bold header row with background
319
+ sheet.addRow(["Month", "Revenue", "Notes"], {
320
+ bold: true,
321
+ backgroundColor: "#DDDDDD",
322
+ align: "center",
323
+ });
324
+
325
+ // Mixed: row default + per-cell override
326
+ sheet.addRow([
327
+ "January",
328
+ { value: 12500, type: "float", color: "#006600" }, // green text on this cell only
329
+ "On track",
330
+ ], { italic: true });
331
+ ```
332
+
333
+ Available formatting options: `bold`, `italic`, `fontSize`, `fontFamily`, `color`, `underline`, `backgroundColor`, `border`, `borderTop/Bottom/Left/Right`, `align`, `verticalAlign`, `padding`, `wrap`.
334
+
335
+ ### Date formatting
336
+
337
+ ```typescript
338
+ // Document-level default
339
+ doc.setDateFormat("DD/MM/YYYY"); // "YYYY-MM-DD" | "DD/MM/YYYY" | "MM/DD/YYYY"
340
+
341
+ // Per-row or per-cell override
342
+ sheet.addRow([{ value: new Date("2026-12-25"), type: "date", dateFormat: "MM/DD/YYYY" }]);
343
+ ```
344
+
345
+ The `office:date-value` attribute always stores the ISO date — display format is separate.
346
+
347
+ ### Column widths and row heights
348
+
349
+ ```typescript
350
+ sheet.setColumnWidth(0, "4cm");
351
+ sheet.setColumnWidth(1, "8cm");
352
+
353
+ sheet.addRow(["Header"]);
354
+ sheet.setRowHeight(0, "1.5cm");
355
+ ```
356
+
357
+ ### Multiple sheets
358
+
359
+ ```typescript
360
+ const doc = new OdsDocument();
361
+ doc.setMetadata({ title: "Annual Report", creator: "Acme Corp" });
362
+
363
+ const q1 = doc.addSheet("Q1");
364
+ q1.addRow(["Month", "Revenue"], { bold: true });
365
+ q1.addRow(["January", 12500]);
366
+ q1.addRow(["March", 14800]);
367
+
368
+ const q2 = doc.addSheet("Q2");
369
+ q2.addRow(["Month", "Revenue"], { bold: true });
370
+ q2.addRow(["April", 15300]);
371
+
372
+ const bytes = await doc.save();
373
+ ```
374
+
375
+ ---
376
+
274
377
  ## Fill: template engine
275
378
 
276
379
  Create a `.odt` template in LibreOffice with `{placeholders}`, then fill it programmatically.
@@ -435,6 +538,41 @@ See the [complete ODT to PDF with Typst guide](https://githubnewbie0.github.io/o
435
538
  | `addPageBreak()` | Insert page break |
436
539
  | `save()` | Generate `.odt` as `Promise<Uint8Array>` |
437
540
 
541
+ ### OdsDocument
542
+
543
+ | Method | Description |
544
+ |--------|-------------|
545
+ | `setMetadata(options)` | Set title, creator, description |
546
+ | `setDateFormat(format)` | Set default date display format (`"YYYY-MM-DD"` \| `"DD/MM/YYYY"` \| `"MM/DD/YYYY"`) |
547
+ | `addSheet(name)` | Add a sheet tab — returns `OdsSheet` |
548
+ | `save()` | Generate `.ods` as `Promise<Uint8Array>` |
549
+
550
+ ### OdsSheet
551
+
552
+ | Method | Description |
553
+ |--------|-------------|
554
+ | `addRow(values, options?)` | Add a row of cells with optional formatting defaults |
555
+ | `setColumnWidth(colIndex, width)` | Set column width (e.g. `"4cm"`) |
556
+ | `setRowHeight(rowIndex, height)` | Set row height (e.g. `"1cm"`) |
557
+
558
+ ### OdsCellValue
559
+
560
+ ```typescript
561
+ type OdsCellValue =
562
+ | string // → string cell
563
+ | number // → float cell
564
+ | boolean // → boolean cell
565
+ | Date // → date cell
566
+ | null // → empty cell
567
+ | undefined // → empty cell
568
+ | OdsCellObject; // → explicit type (required for formulas)
569
+
570
+ interface OdsCellObject extends OdsCellOptions {
571
+ value: string | number | boolean | Date | null;
572
+ type: "string" | "float" | "date" | "boolean" | "formula";
573
+ }
574
+ ```
575
+
438
576
  ### fillTemplate
439
577
 
440
578
  ```typescript
@@ -536,9 +674,10 @@ ESM only. Zero Node-specific APIs in the library source — enforced at the Type
536
674
 
537
675
  - **Single runtime dependency** — fflate for ZIP. No transitive dependencies.
538
676
  - **Spec-compliant output** — every generated file passes the OASIS ODF validator. Enforced on every commit by CI.
539
- - **Four complete capability modes** — build, fill, read, convert. Not just generation.
677
+ - **Multiple ODF formats** — ODT documents and ODS spreadsheets from the same library.
678
+ - **Five complete capability modes** — build ODT, build ODS, fill templates, read, convert. Not just generation.
540
679
  - **Zero-dependency Typst emitter** — the only JavaScript library with built-in ODT→Typst conversion for PDF generation.
541
- - **TypeScript-first** — full types across all three sub-exports.
680
+ - **TypeScript-first** — full types across all sub-exports.
542
681
  - **Apache 2.0** — use freely in commercial and open source projects.
543
682
 
544
683
  ---
@@ -548,6 +687,7 @@ ESM only. Zero Node-specific APIs in the library source — enforced at the Type
548
687
  | Feature | odf-kit | simple-odf | docxtemplater |
549
688
  |---------|---------|------------|---------------|
550
689
  | Generate .odt from scratch | ✅ | ⚠️ flat XML only | ❌ |
690
+ | Generate .ods from scratch | ✅ | ❌ | ❌ |
551
691
  | Fill .odt templates | ✅ | ❌ | ✅ .docx only |
552
692
  | Read .odt files | ✅ | ❌ | ❌ |
553
693
  | Convert to HTML | ✅ | ❌ | ❌ |
@@ -566,6 +706,8 @@ odf-kit targets ODF 1.2 (ISO/IEC 26300). Generated files include proper ZIP pack
566
706
 
567
707
  ## Version history
568
708
 
709
+ **v0.9.0** — ODS spreadsheet generation: `OdsDocument`, multiple sheets, auto-typed cells, formulas, date formatting (ISO/DMY/MDY), row and cell formatting, column widths, row heights, style deduplication. 707 tests passing.
710
+
569
711
  **v0.8.0** — `odf-kit/typst` sub-export: `odtToTypst()` and `modelToTypst()`. Zero-dependency ODT→Typst emitter for PDF generation via Typst CLI. 650+ tests passing.
570
712
 
571
713
  **v0.7.0** — Tier 3 reader: paragraph styles, page geometry, headers/footers (all four zones), sections, tracked changes (all three ODF modes). `SectionNode`, `TrackedChangeNode` added to `BodyNode` union.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "odf-kit",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Generate, fill, read, and convert OpenDocument Format (.odt) files in JavaScript and TypeScript. Works in Node.js and browsers.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -14,6 +14,10 @@
14
14
  "types": "./dist/odt/index.d.ts",
15
15
  "import": "./dist/odt/index.js"
16
16
  },
17
+ "./ods": {
18
+ "types": "./dist/ods/index.d.ts",
19
+ "import": "./dist/ods/index.js"
20
+ },
17
21
  "./template": {
18
22
  "types": "./dist/template/index.d.ts",
19
23
  "import": "./dist/template/index.js"