@evotecit/officeimo 0.0.0-stage → 0.1.1
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.
- package/LICENSE +21 -0
- package/README.md +1222 -2
- package/bundles/officeimo-canopyx.js +11741 -0
- package/bundles/officeimo-canopyx.mjs +11639 -0
- package/bundles/officeimo-csv.js +1264 -0
- package/bundles/officeimo-csv.mjs +1239 -0
- package/bundles/officeimo-datatables.js +12018 -0
- package/bundles/officeimo-datatables.mjs +11915 -0
- package/bundles/officeimo-execution.js +1513 -0
- package/bundles/officeimo-execution.mjs +1489 -0
- package/bundles/officeimo-pdf.js +7009 -0
- package/bundles/officeimo-pdf.mjs +6946 -0
- package/bundles/officeimo-xlsx.js +5344 -0
- package/bundles/officeimo-xlsx.mjs +5290 -0
- package/bundles/officeimo.js +11468 -0
- package/bundles/officeimo.mjs +11369 -0
- package/dist/core/dates.d.ts +1 -0
- package/dist/core/dates.js +16 -0
- package/dist/core/errors.d.ts +12 -0
- package/dist/core/errors.js +31 -0
- package/dist/core/grouped-report.d.ts +87 -0
- package/dist/core/grouped-report.js +252 -0
- package/dist/core/index.d.ts +74 -0
- package/dist/core/index.js +37 -0
- package/dist/core/iteration.d.ts +7 -0
- package/dist/core/iteration.js +149 -0
- package/dist/core/limits.d.ts +7 -0
- package/dist/core/limits.js +56 -0
- package/dist/core/links.d.ts +5 -0
- package/dist/core/links.js +14 -0
- package/dist/core/presentation.d.ts +29 -0
- package/dist/core/presentation.js +59 -0
- package/dist/core/progress.d.ts +1 -0
- package/dist/core/progress.js +10 -0
- package/dist/core/sinks.d.ts +33 -0
- package/dist/core/sinks.js +102 -0
- package/dist/core/table.d.ts +8 -0
- package/dist/core/table.js +1 -0
- package/dist/core/value-text.d.ts +7 -0
- package/dist/core/value-text.js +13 -0
- package/dist/csv/index.d.ts +44 -0
- package/dist/csv/index.js +133 -0
- package/dist/csv/options.d.ts +1 -0
- package/dist/csv/options.js +8 -0
- package/dist/csv/structured-rows.d.ts +3 -0
- package/dist/csv/structured-rows.js +15 -0
- package/dist/execution/host.d.ts +5 -0
- package/dist/execution/host.js +164 -0
- package/dist/execution/index.d.ts +3 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/protocol.d.ts +48 -0
- package/dist/execution/protocol.js +173 -0
- package/dist/execution/types.d.ts +42 -0
- package/dist/execution/types.js +1 -0
- package/dist/execution/worker.d.ts +3 -0
- package/dist/execution/worker.js +147 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +14 -0
- package/dist/integrations/canopyx/dates.d.ts +1 -0
- package/dist/integrations/canopyx/dates.js +34 -0
- package/dist/integrations/canopyx/index.d.ts +10 -0
- package/dist/integrations/canopyx/index.js +45 -0
- package/dist/integrations/canopyx/source.d.ts +3 -0
- package/dist/integrations/canopyx/source.js +122 -0
- package/dist/integrations/canopyx/types.d.ts +83 -0
- package/dist/integrations/canopyx/types.js +1 -0
- package/dist/integrations/datatables/api.d.ts +1 -0
- package/dist/integrations/datatables/api.js +27 -0
- package/dist/integrations/datatables/headings.d.ts +1 -0
- package/dist/integrations/datatables/headings.js +65 -0
- package/dist/integrations/datatables/index.d.ts +12 -0
- package/dist/integrations/datatables/index.js +167 -0
- package/dist/integrations/datatables/snapshot.d.ts +3 -0
- package/dist/integrations/datatables/snapshot.js +206 -0
- package/dist/integrations/datatables/types.d.ts +98 -0
- package/dist/integrations/datatables/types.js +1 -0
- package/dist/integrations/options.d.ts +13 -0
- package/dist/integrations/options.js +34 -0
- package/dist/internal/capture.d.ts +4 -0
- package/dist/internal/capture.js +14 -0
- package/dist/internal/columns.d.ts +27 -0
- package/dist/internal/columns.js +1 -0
- package/dist/internal/crc32.d.ts +6 -0
- package/dist/internal/crc32.js +17 -0
- package/dist/internal/export-values.d.ts +3 -0
- package/dist/internal/export-values.js +14 -0
- package/dist/internal/rows.d.ts +6 -0
- package/dist/internal/rows.js +77 -0
- package/dist/internal/table-spans.d.ts +11 -0
- package/dist/internal/table-spans.js +58 -0
- package/dist/internal/totals.d.ts +15 -0
- package/dist/internal/totals.js +42 -0
- package/dist/opc/index.d.ts +67 -0
- package/dist/opc/index.js +233 -0
- package/dist/opc/properties.d.ts +15 -0
- package/dist/opc/properties.js +18 -0
- package/dist/opc/uri.d.ts +5 -0
- package/dist/opc/uri.js +41 -0
- package/dist/pdf/annotations.d.ts +1 -0
- package/dist/pdf/annotations.js +38 -0
- package/dist/pdf/binary.d.ts +6 -0
- package/dist/pdf/binary.js +24 -0
- package/dist/pdf/document-drawings.d.ts +15 -0
- package/dist/pdf/document-drawings.js +237 -0
- package/dist/pdf/document-grouped.d.ts +1 -0
- package/dist/pdf/document-grouped.js +244 -0
- package/dist/pdf/document-images.d.ts +19 -0
- package/dist/pdf/document-images.js +125 -0
- package/dist/pdf/document-types.d.ts +160 -0
- package/dist/pdf/document-types.js +1 -0
- package/dist/pdf/document-vectors.d.ts +11 -0
- package/dist/pdf/document-vectors.js +77 -0
- package/dist/pdf/document.d.ts +9 -0
- package/dist/pdf/document.js +270 -0
- package/dist/pdf/drawing-types.d.ts +53 -0
- package/dist/pdf/drawing-types.js +1 -0
- package/dist/pdf/font-resources.d.ts +43 -0
- package/dist/pdf/font-resources.js +202 -0
- package/dist/pdf/font-support.d.ts +1 -0
- package/dist/pdf/font-support.js +60 -0
- package/dist/pdf/font.d.ts +17 -0
- package/dist/pdf/font.js +56 -0
- package/dist/pdf/grouped-table.d.ts +6 -0
- package/dist/pdf/grouped-table.js +40 -0
- package/dist/pdf/grouped-types.d.ts +34 -0
- package/dist/pdf/grouped-types.js +1 -0
- package/dist/pdf/grouped.d.ts +10 -0
- package/dist/pdf/grouped.js +37 -0
- package/dist/pdf/index.d.ts +22 -0
- package/dist/pdf/index.js +8 -0
- package/dist/pdf/inline-text.d.ts +30 -0
- package/dist/pdf/inline-text.js +183 -0
- package/dist/pdf/inline-types.d.ts +15 -0
- package/dist/pdf/inline-types.js +1 -0
- package/dist/pdf/list-layout.d.ts +6 -0
- package/dist/pdf/list-layout.js +49 -0
- package/dist/pdf/objects.d.ts +2 -0
- package/dist/pdf/objects.js +320 -0
- package/dist/pdf/outlines.d.ts +1 -0
- package/dist/pdf/outlines.js +55 -0
- package/dist/pdf/page-context.d.ts +1 -0
- package/dist/pdf/page-context.js +12 -0
- package/dist/pdf/pages.d.ts +1 -0
- package/dist/pdf/pages.js +678 -0
- package/dist/pdf/paragraph-layout.d.ts +21 -0
- package/dist/pdf/paragraph-layout.js +71 -0
- package/dist/pdf/paragraph-styles.d.ts +1 -0
- package/dist/pdf/paragraph-styles.js +66 -0
- package/dist/pdf/png.d.ts +9 -0
- package/dist/pdf/png.js +259 -0
- package/dist/pdf/preflight.d.ts +7 -0
- package/dist/pdf/preflight.js +32 -0
- package/dist/pdf/presentation-settings.d.ts +5 -0
- package/dist/pdf/presentation-settings.js +28 -0
- package/dist/pdf/providers/harfbuzz.d.ts +60 -0
- package/dist/pdf/providers/harfbuzz.js +112 -0
- package/dist/pdf/providers/unicode13-profile.d.ts +2 -0
- package/dist/pdf/providers/unicode13-profile.js +115 -0
- package/dist/pdf/section-types.d.ts +15 -0
- package/dist/pdf/section-types.js +40 -0
- package/dist/pdf/session.d.ts +25 -0
- package/dist/pdf/session.js +55 -0
- package/dist/pdf/settings.d.ts +17 -0
- package/dist/pdf/settings.js +196 -0
- package/dist/pdf/shaped-text.d.ts +5 -0
- package/dist/pdf/shaped-text.js +205 -0
- package/dist/pdf/standard-widths.d.ts +1 -0
- package/dist/pdf/standard-widths.js +317 -0
- package/dist/pdf/structure-parent-tree.d.ts +1 -0
- package/dist/pdf/structure-parent-tree.js +57 -0
- package/dist/pdf/structure.d.ts +6 -0
- package/dist/pdf/structure.js +302 -0
- package/dist/pdf/table-band-flow.d.ts +34 -0
- package/dist/pdf/table-band-flow.js +129 -0
- package/dist/pdf/table-band-plan.d.ts +10 -0
- package/dist/pdf/table-band-plan.js +83 -0
- package/dist/pdf/table-layout.d.ts +75 -0
- package/dist/pdf/table-layout.js +217 -0
- package/dist/pdf/table-structure.d.ts +1 -0
- package/dist/pdf/table-structure.js +108 -0
- package/dist/pdf/text-shaping-types.d.ts +39 -0
- package/dist/pdf/text-shaping-types.js +1 -0
- package/dist/pdf/text.d.ts +13 -0
- package/dist/pdf/text.js +101 -0
- package/dist/pdf/truetype-subset.d.ts +5 -0
- package/dist/pdf/truetype-subset.js +217 -0
- package/dist/pdf/truetype.d.ts +1 -0
- package/dist/pdf/truetype.js +235 -0
- package/dist/pdf/types.d.ts +171 -0
- package/dist/pdf/types.js +1 -0
- package/dist/pdf/write.d.ts +6 -0
- package/dist/pdf/write.js +57 -0
- package/dist/pdf/xref.d.ts +1 -0
- package/dist/pdf/xref.js +30 -0
- package/dist/xlsx/attachments.d.ts +30 -0
- package/dist/xlsx/attachments.js +67 -0
- package/dist/xlsx/chart-bindings.d.ts +1 -0
- package/dist/xlsx/chart-bindings.js +122 -0
- package/dist/xlsx/chart-types.d.ts +73 -0
- package/dist/xlsx/chart-types.js +1 -0
- package/dist/xlsx/chart-xml.d.ts +2 -0
- package/dist/xlsx/chart-xml.js +103 -0
- package/dist/xlsx/charts.d.ts +1 -0
- package/dist/xlsx/charts.js +159 -0
- package/dist/xlsx/conditional-formatting.d.ts +1 -0
- package/dist/xlsx/conditional-formatting.js +158 -0
- package/dist/xlsx/conditional-types.d.ts +64 -0
- package/dist/xlsx/conditional-types.js +1 -0
- package/dist/xlsx/data-row-ranges.d.ts +5 -0
- package/dist/xlsx/data-row-ranges.js +39 -0
- package/dist/xlsx/differential-styles.d.ts +1 -0
- package/dist/xlsx/differential-styles.js +102 -0
- package/dist/xlsx/formula.d.ts +8 -0
- package/dist/xlsx/formula.js +104 -0
- package/dist/xlsx/grouped-layout.d.ts +61 -0
- package/dist/xlsx/grouped-layout.js +79 -0
- package/dist/xlsx/grouped.d.ts +16 -0
- package/dist/xlsx/grouped.js +161 -0
- package/dist/xlsx/index.d.ts +24 -0
- package/dist/xlsx/index.js +10 -0
- package/dist/xlsx/layout.d.ts +1 -0
- package/dist/xlsx/layout.js +186 -0
- package/dist/xlsx/options.d.ts +1 -0
- package/dist/xlsx/options.js +16 -0
- package/dist/xlsx/portable.d.ts +27 -0
- package/dist/xlsx/portable.js +44 -0
- package/dist/xlsx/preservation.d.ts +1 -0
- package/dist/xlsx/preservation.js +60 -0
- package/dist/xlsx/ranges.d.ts +1 -0
- package/dist/xlsx/ranges.js +24 -0
- package/dist/xlsx/regions.d.ts +1 -0
- package/dist/xlsx/regions.js +97 -0
- package/dist/xlsx/structured-rows.d.ts +11 -0
- package/dist/xlsx/structured-rows.js +28 -0
- package/dist/xlsx/style-xml.d.ts +1 -0
- package/dist/xlsx/style-xml.js +6 -0
- package/dist/xlsx/styles.d.ts +70 -0
- package/dist/xlsx/styles.js +203 -0
- package/dist/xlsx/table.d.ts +12 -0
- package/dist/xlsx/table.js +35 -0
- package/dist/xlsx/types.d.ts +180 -0
- package/dist/xlsx/types.js +1 -0
- package/dist/xlsx/validation-types.d.ts +18 -0
- package/dist/xlsx/validation-types.js +1 -0
- package/dist/xlsx/validation.d.ts +1 -0
- package/dist/xlsx/validation.js +92 -0
- package/dist/xlsx/values.d.ts +13 -0
- package/dist/xlsx/values.js +87 -0
- package/dist/xlsx/workbook.d.ts +50 -0
- package/dist/xlsx/workbook.js +452 -0
- package/dist/xlsx/worksheet.d.ts +71 -0
- package/dist/xlsx/worksheet.js +700 -0
- package/dist/xlsx/write.d.ts +15 -0
- package/dist/xlsx/write.js +47 -0
- package/dist/xml/index.d.ts +24 -0
- package/dist/xml/index.js +74 -0
- package/dist/zip/entry.d.ts +39 -0
- package/dist/zip/entry.js +122 -0
- package/dist/zip/index.d.ts +44 -0
- package/dist/zip/index.js +248 -0
- package/package.json +104 -4
package/README.md
CHANGED
|
@@ -1,3 +1,1223 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OfficeIMO JavaScript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@evotecit/officeimo` provides strict TypeScript document libraries for evergreen browsers, Web Workers and Node 22, 24, 25 and 26. It writes streaming XLSX workbooks, UTF-8 CSV and paginated PDF tables with no runtime dependencies. One package owns seven public layers: `core`, `zip`, `xml`, `opc`, `xlsx`, `csv` and `pdf`. The optional `execution` entry connects host-owned workers to those writers with bounded row and byte messages.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Install the npm archive in your JavaScript application:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install /path/to/evotecit-officeimo-0.1.0.tgz
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
To produce the archive from this package's source directory:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm ci
|
|
17
|
+
npm run build
|
|
18
|
+
npm pack --pack-destination /path/to/local-packages
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`tsc` produces ES modules and declarations in `dist/`. The archive contains those files, portable bundles, this README and the MIT license. TypeScript is a development dependency; installing the archive as an application dependency installs no compiler or runtime packages.
|
|
22
|
+
|
|
23
|
+
## Export a table
|
|
24
|
+
|
|
25
|
+
Use the same columns for XLSX, CSV and PDF. Object columns select a typed key or compute a synchronous value; array rows use positional columns. A getter can return `ExportCell` to keep a typed value together with display text and presentation.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { writeXlsx, writeCsv, ExportCell, saveBlob } from "@evotecit/officeimo";
|
|
29
|
+
import type { Column } from "@evotecit/officeimo";
|
|
30
|
+
|
|
31
|
+
interface Sale { customer: { name: string }; amount: number; seen: Date; }
|
|
32
|
+
const columns = [
|
|
33
|
+
{ header: "Customer", key: "customerName", value: (row: Sale) => row.customer.name },
|
|
34
|
+
{ header: "Amount", key: "amount", type: "number", format: "0.00",
|
|
35
|
+
value: (row: Sale) => new ExportCell(row.amount, {
|
|
36
|
+
text: row.amount.toFixed(2) + " USD",
|
|
37
|
+
presentation: row.amount < 0 ? { background: "FFC7CE" } : {}
|
|
38
|
+
}) },
|
|
39
|
+
{ header: "Seen", key: "seen", type: "date", format: "yyyy-mm-dd" }
|
|
40
|
+
] satisfies readonly Column<Sale>[];
|
|
41
|
+
const rows: Sale[] = [{ customer: { name: "Łódź 🧪" }, amount: 12.5, seen: new Date() }];
|
|
42
|
+
|
|
43
|
+
saveBlob(await writeXlsx(rows, {
|
|
44
|
+
columns, dateMode: "utc",
|
|
45
|
+
sheet: { name: "Sales", table: {}, freezeHeader: true }
|
|
46
|
+
}), "sales.xlsx");
|
|
47
|
+
saveBlob(await writeCsv(rows, { columns }), "sales.csv");
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`Column<Sale>` checks literal keys against `Sale`. Getters support nested fields and calculated values; their optional `key` is a stable report identifier for totals and conditional ranges. Unselected domain fields can be arbitrary objects. Arrays are positional unless every column has a getter; that explicit projection can select from a wider array. Dots in literal keys do not traverse objects. TypeScript 5.4 or newer is required for the typed writer signatures.
|
|
51
|
+
|
|
52
|
+
| Task | Entry point | Completion |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| One Excel table | `writeXlsx(rows, options)` | `Blob` |
|
|
55
|
+
| One CSV table | `writeCsv(rows, options)` | `Blob` |
|
|
56
|
+
| One paginated PDF table | `writePdf(rows, options)` | `Blob` |
|
|
57
|
+
| Write a table to a destination | `writeXlsxTo(rows, destination, options)` / `writeCsvTo(...)` / `writePdfTo(...)` | `{ rows, columns, bytes }` |
|
|
58
|
+
| Multiple worksheets, registered styles, images or extra parts | `new Workbook(options)`, `addWorksheet`, `addRows` | `toBlob()` or streamed `finish()` |
|
|
59
|
+
| Export an installed DataTables grid | Optional integration below | Same writers and destination ownership |
|
|
60
|
+
| Export a CanopyX record capture | `exportCanopy` / `writeCanopyTo` in the optional CanopyX entry | `Blob` or streamed `{ rows, columns, bytes }` |
|
|
61
|
+
|
|
62
|
+
The table writers accept synchronous iterables and async iterables. XLSX defaults to the sheet name `Data`, a bold header, filtering when a header is present, and width sampling of up to 100 rows clamped to 6–54 characters. `sheet` supplies the existing worksheet layout options. Workbook-local style indexes belong to the advanced `Workbook` API; portable `ExportCell` presentation and row/cell style patches work with the table helper.
|
|
63
|
+
|
|
64
|
+
An `ExportCell` can carry an external link alongside its typed value, display text and presentation:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
new ExportCell(12.5, {
|
|
68
|
+
text: "12.50 USD",
|
|
69
|
+
presentation: { color: "0563C1" },
|
|
70
|
+
link: { target: "https://example.com/invoices/42", tooltip: "Open invoice 42" }
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
XLSX keeps the numeric value and writes a cell hyperlink. PDF renders the display text and writes a native link annotation over each cell fragment, including fragments continued onto another page. CSV keeps its selected raw/display value mode. Links accept absolute HTTP, HTTPS and mailto targets; credentials, whitespace and other schemes are rejected. Resolve relative report links against an explicit host base before creating the cell. The target and tooltip are copied when the cell is created, and links do not add automatic font styling. An XLSX cell using the oversized-text preservation link cannot also carry an external link; that conflict fails explicitly.
|
|
75
|
+
|
|
76
|
+
An async generator is consumed once. Use a source factory for separate exports rather than passing the same generator twice:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
async function* loadSales(): AsyncGenerator<Sale> {
|
|
80
|
+
// Fetch pages here and yield typed Sale records, including Date values.
|
|
81
|
+
for (const row of rows) yield row;
|
|
82
|
+
}
|
|
83
|
+
const excel = await writeXlsx(loadSales(), { columns });
|
|
84
|
+
const csv = await writeCsv(loadSales(), { columns, valueMode: "display" });
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Data callbacks use zero-based `rowIndex` and `columnIndex`, excluding titles, headings and totals. XLSX additionally supplies one-based `worksheetRow` and `sheetName`. A getter runs once per selected cell per export, before formatting, preservation and resource checks on the resolved value. Getters are synchronous; perform asynchronous loading in the row source. Missing object values produce empty cells. Invalid nested objects, asynchronous getter results and extra unprojected array values fail visibly.
|
|
88
|
+
|
|
89
|
+
## DataTables Excel, CSV and PDF exports
|
|
90
|
+
|
|
91
|
+
The optional `@evotecit/officeimo/integrations/datatables` entry connects an installed DataTables/Buttons instance to the XLSX, CSV and PDF writers. It imports neither DataTables nor jQuery and uses no third-party document writer. Importing the main OfficeIMO package does not load the integration.
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import DataTable from "datatables.net";
|
|
95
|
+
import "datatables.net-buttons";
|
|
96
|
+
import { registerDataTablesButtons } from "@evotecit/officeimo/integrations/datatables";
|
|
97
|
+
|
|
98
|
+
registerDataTablesButtons(DataTable, {
|
|
99
|
+
exportOptions: { columns: ":visible" },
|
|
100
|
+
columnOptions: { 2: { type: "number", format: "0.00" } },
|
|
101
|
+
xlsx: { sheet: { table: { style: "TableStyleMedium2" }, freezeHeader: true } },
|
|
102
|
+
onError: error => console.error("Export failed", error)
|
|
103
|
+
});
|
|
104
|
+
const table = new DataTable("#report", {
|
|
105
|
+
layout: { topStart: { buttons: [
|
|
106
|
+
{ extend: "officeimoExcel", filename: "Report" },
|
|
107
|
+
{ extend: "officeimoCsv", filename: "Report" },
|
|
108
|
+
{ extend: "officeimoPdf", filename: "Report", orientation: "landscape" }
|
|
109
|
+
] } }
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Register once, after installing Buttons. Processing clears when saving completes or before calling `onError`. The default destination downloads a Blob; `save(blob, filename)` replaces delivery. Each button can override registration options through its `officeimo` property. Familiar `filename`, `exportOptions` and `footer: false` properties are supported. Filename patterns use Buttons' `exportInfo()` title substitution and sanitization: `"*"` uses the document title, and a synchronous `filename(configuration, table)` callback can return a pattern. Excel and CSV buttons reject native `customize`, `header: false`, `title`, `messageTop` and `messageBottom`; express Excel report layout through `officeimo.xlsx.sheet`. The PDF button accepts the title, messages and heading settings described below, with typed layout options in `officeimo.pdf`.
|
|
114
|
+
|
|
115
|
+
For application-owned buttons, `exportDataTable(DataTable, table, "xlsx" | "csv" | "pdf", options)` returns a Blob. `writeDataTableTo(DataTable, table, format, destination, options)` accepts a caller-owned `ByteSink` or `WritableStream<Uint8Array>` and returns `{ rows, columns, bytes }`. Both accept `signal`, `onProgress`, shared resource `limits`, and format-specific `xlsx`, `csv` or `pdf` options. XLSX uses the same settings as `writeXlsx`: set workbook policy through `xlsx.dateMode` and report layout or the worksheet name through `xlsx.sheet`, for example `xlsx: { dateMode: "utc", sheet: { name: "Inventory", freezeHeader: true } }`. A defined numeric shared limit overrides its matching format limit; `undefined` leaves that format's ceiling intact. XLSX defaults to a bold header, filtering and bounded width sampling of up to 100 rows, clamped to 6–54 characters. Explicit column widths avoid sampling that column.
|
|
116
|
+
|
|
117
|
+
`project(value, { rowIndex, columnIndex, sourceRowIndex, sourceColumnIndex })` resolves each rendered/normalized value into a scalar or an `ExportCell`. Data indexes are zero-based positions in the selected export; source indexes identify DataTables rows/columns. `columnOptions` is keyed by DataTables column index. Use an orthogonal renderer for raw numbers/dates when display text contains currency, markup or localized dates. The adapter does not infer types from formatted strings. For example:
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
import { exportDataTable, ExportCell } from "@evotecit/officeimo/integrations/datatables";
|
|
121
|
+
const controller = new AbortController();
|
|
122
|
+
const blob = await exportDataTable(DataTable, table, "xlsx", {
|
|
123
|
+
signal: controller.signal,
|
|
124
|
+
exportOptions: { columns: ":visible", orthogonal: "export", modifier: { selected: null } },
|
|
125
|
+
columnOptions: { 2: { type: "number", format: "0.00" } },
|
|
126
|
+
project: (value, cell) => cell.sourceColumnIndex === 2
|
|
127
|
+
? new ExportCell(value, { presentation: { background: "E2F0D9" } }) : value,
|
|
128
|
+
limits: { maxRows: 100000, maxCells: 2000000, maxOutputBytes: 100000000 }
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
CSS classes and computed DOM styles are not copied automatically. CSV retains values or explicit display text and formula protection; it cannot carry colors or Excel layout.
|
|
133
|
+
|
|
134
|
+
| Contract | Batched mode, the default | Compatibility mode |
|
|
135
|
+
| --- | --- | --- |
|
|
136
|
+
| Row/column selectors, search/order modifiers | Captured through public DataTables APIs | Passed to `buttons.exportData()` |
|
|
137
|
+
| Select extension | Selected rows when a selection exists; `selected: null` exports all matching rows | Same installed Buttons behavior |
|
|
138
|
+
| Orthogonal rendering and synchronous `format.header/body/footer` | Supported; cleanup uses installed `Buttons.stripData` | Supported by installed Buttons |
|
|
139
|
+
| Whole-matrix `customizeData` | Rejected | Supported; cannot combine with source-index `project` |
|
|
140
|
+
| Body memory | Selected row indexes and bounded cell batches | Complete Buttons matrix, then batched writing |
|
|
141
|
+
| Horizontal grouped headers | Preserved through shared column group paths | Same |
|
|
142
|
+
| Vertical spans, blank spanning groups, adjacent separate equal group paths | PDF preserves structured headings by default. XLSX/CSV preserve them with `headings: "structured"`; CSV also needs an explicit span rule. `headings: "leaf"` selects one heading row | Same |
|
|
143
|
+
| Footers | Structured exports preserve up to 16 physical rows; XLSX native table/filter constraints and CSV flattening apply. `includeFooter: false` omits footers | Same |
|
|
144
|
+
| Server-side processing | Rejected unless `serverSide: "loaded"` acknowledges loaded rows only | Same |
|
|
145
|
+
|
|
146
|
+
Qualified pairs are DataTables 2.3.7/Buttons 3.2.6 and DataTables 3.1.3/Buttons 4.1.2, including Select and ColReorder. TypeScript 5.9.3 consumer checks use bundler resolution. The newer pair has duplicate upstream declaration index signatures and requires `skipLibCheck`; OfficeIMO's declarations remain strictly checked. This declaration limit is separate from browser interoperability.
|
|
147
|
+
|
|
148
|
+
`createDataTablesExport(DataTable, table, options)` exposes readonly `columns`, heading rows, optional footer, `rowCount` and a single-use async `rows` source. `headings: "structured"` additionally exposes `headerStructure`/`footerStructure` for the writers' span matrices. Selection/headings are captured immediately; batched body values are read during iteration. Each batch replaces bounded cell indexes through public API result-set operations, without rescanning the table's rows. Batched exports require one table per API instance. Keep table data and column layout stable until export finishes. `batchRows` defaults to 4,096; `maxBatchCells` defaults to 65,536, can lower the effective row count per batch and must fit one row. Cancellation is checked between cells and yielding occurs during formatting and between batches. A synchronous DataTables renderer cannot be interrupted while it runs.
|
|
149
|
+
|
|
150
|
+
For an XLSX heading whose final physical row contains a merged or covered cell, use `headings: "structured", xlsx: { sheet: { autoFilter: false } }`. Native filters and Excel tables require an unmerged final row matching the declared column labels. Structured footer rows sit outside a native table. For CSV, choose `headings: "structured", csv: { spanMode: "repeat" }` to repeat each anchor across its covered positions, or `"anchors"` to leave covered fields empty. Each physical row is retained. Existing grouped defaults remain unchanged.
|
|
151
|
+
|
|
152
|
+
The PDF button accepts native `title`, `messageTop`, `messageBottom`, `pageSize`, `orientation`, `header: false` and `footer: false` settings. Omitted titles/messages inherit registration defaults; an explicit `null` clears that field. Text and filename resolution use the installed Buttons API. Supply writer options through `pdf` in registration defaults, or `officeimo: { pdf: ... }` on one button. Per-button PDF settings override only the supplied fields, retaining omitted fonts, metadata and layout settings; nested font profiles and footer objects replace their whole field. Native `header: false` and `footer: false` also suppress replacement table headings and footers. Native document-definition `customize` callbacks are rejected; use typed PDF options and portable `ExportCell` presentation. `pdf.footer` replaces the grid's footer when supplied. Unicode PDF exports require `pdf.fonts`, as described below.
|
|
153
|
+
|
|
154
|
+
Compressed PDF streams write output chunks progressively with an indirect length. Tagged reports serialize completed logical rows, paragraphs and graphics during export, retaining open content and compact references needed by the PDF object graph. ParentTree indexing uses bounded nodes. Total PDF memory still includes fonts, images, the current page, object offsets and retained parent references; Blob output additionally retains the completed file. Resource limits remain cumulative across completed structures.
|
|
155
|
+
|
|
156
|
+
Direct sink output avoids retaining the finished file. Blob exports and registered download buttons retain it; caller-owned sinks own partial bytes after failure. The grid still holds its input. Server-side full-data export needs an application-owned paged source passed directly to the writers with the server's filter/order contract.
|
|
157
|
+
|
|
158
|
+
DataTables and its DOM stay on the page. A host-owned worker can consume portable columns and bounded row batches from the source: request/acknowledge batches and output chunks rather than cloning the full matrix. Reconstruct `ExportCell` in the worker because structured cloning loses its brand. The [verification guide](../Build/BrowserExports/README.md#datatables-integration-and-comparisons) covers workers, cancellation, fallback and reproducible comparisons. Measurements describe the tested workload/browser, without a universal speed claim.
|
|
159
|
+
|
|
160
|
+
## CanopyX record exports
|
|
161
|
+
|
|
162
|
+
The optional `@evotecit/officeimo/integrations/canopyx` entry consumes CanopyX's immutable `prepareExport` capture. CanopyX owns the accepted query, column order, selection, source paging, revision checks and resolved presentation. OfficeIMO owns file generation. Neither package imports the other at runtime, and importing the main OfficeIMO package does not load the adapter.
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { exportCanopy } from "@evotecit/officeimo/integrations/canopyx";
|
|
166
|
+
|
|
167
|
+
const capture = grid.prepareExport({ scope: "filtered", values: "raw" });
|
|
168
|
+
const reportOptions = {
|
|
169
|
+
tones: {
|
|
170
|
+
neutral: {},
|
|
171
|
+
success: { background: "E2F0D9" },
|
|
172
|
+
warning: { background: "FFF2CC", color: "9C6500" },
|
|
173
|
+
danger: { background: "FFC7CE", color: "9C0006", bold: true }
|
|
174
|
+
},
|
|
175
|
+
columnOptions: {
|
|
176
|
+
amount: { format: "#,##0.00", width: 18 },
|
|
177
|
+
updated: { format: "yyyy-mm-dd hh:mm:ss.000", width: 42, wrapText: true }
|
|
178
|
+
},
|
|
179
|
+
xlsx: { sheet: { title: { text: "Inventory" }, table: {} } },
|
|
180
|
+
limits: { maxRows: 250_000, maxCells: 5_000_000 }
|
|
181
|
+
};
|
|
182
|
+
const blob = await exportCanopy(capture, "xlsx", reportOptions);
|
|
183
|
+
// Deliver the Blob through the host's download or storage policy.
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
`exportCanopy(capture, format, options)` accepts `"xlsx"`, `"csv"` or `"pdf"`. `writeCanopyTo(capture, format, destination, options)` writes to a caller-owned sink or `WritableStream`; failed partial output remains caller-owned. Format options live in `xlsx`, `csv` and `pdf`, with common cancellation, limits and progress at the top level. Common limits override matching format limits. For Unicode PDF text, supply embedding-permitted TrueType fonts through `pdf.fonts`.
|
|
187
|
+
|
|
188
|
+
`createCanopyExport` retains `type: "number"` for native numeric columns in a raw capture, so grouped metrics can use its columns directly. Display captures keep their rendered strings. Datetime metadata remains unforced because the preservation profile can intentionally produce exact ISO text rather than a `Date`.
|
|
189
|
+
|
|
190
|
+
`columnOptions` is keyed by captured column ID. Settings for unselected columns are ignored, so one host format map can serve different visible/selected captures. `PdfFont` is exported from this entry as well as the PDF layer for constructing caller-supplied fonts.
|
|
191
|
+
|
|
192
|
+
| Captured contract | Output behavior |
|
|
193
|
+
| --- | --- |
|
|
194
|
+
| Column IDs, titles and order | Preserved without re-reading the viewport or UI settings |
|
|
195
|
+
| `values: "raw"` | Numeric, boolean and null values remain typed; CSV retains original ISO datetime strings |
|
|
196
|
+
| `values: "display"` | Captured display strings become literal exported values; CSV formula protection still applies |
|
|
197
|
+
| Resolved text | PDF uses it; XLSX retains raw values and uses explicit number/date formats |
|
|
198
|
+
| Semantic tones | Host-supplied portable styles; cell tone overrides overlapping row tone properties |
|
|
199
|
+
| Absolute HTTP(S)/mailto links | Native XLSX relationships and PDF annotations; CSV remains ordinary text |
|
|
200
|
+
| Datetime columns | XLSX defaults to typed dates at exact millisecond precision and literal ISO text for finer precision |
|
|
201
|
+
| CSS pixel width | Never treated as an Excel character width; `columnOptions.width` supplies explicit character widths and `pdf.columnWidths` supplies points |
|
|
202
|
+
| `recordCount` | Used for progress when known and checked against the actual enumeration; unknown counts remain unknown |
|
|
203
|
+
|
|
204
|
+
Excel/PDF reject unsupported presentation diagnostics and unmapped tones by default. The reporting runtime supplies semantic captures. For an ordinary grid, custom renderer or CSS-only presentation, choose `unsupportedPresentation: "text"` to accept the captured text fallback and optionally observe each diagnostic with synchronous `onDiagnostic`. That fallback uses capture data; it does not scrape custom DOM renderer output. CSV defaults to text because the format has no visual styling; choose `"reject"` explicitly when diagnostics should stop it. No unbounded diagnostic list is retained.
|
|
205
|
+
|
|
206
|
+
`datetime: "typed"` requires exact millisecond precision; `"text"` keeps the original ISO value. The default `"preserve"` retains finer timestamps and dates outside Excel's 1900–9999 range as text rather than rounding or dropping them. An ISO value converted to a typed Excel date must carry an explicit time zone. XLSX defaults to the capture's UTC/local clock choice; `xlsx.dateMode` can override it. PDF displays the captured text, and CSV raw mode retains the original string and its zone.
|
|
207
|
+
|
|
208
|
+
`createCanopyExport(capture, format, options)` exposes frozen columns, `rowCount` and fresh `rows()` enumerations for applications using the format writers directly. It retains no whole-table body. Each enumeration passes its cancellation signal into CanopyX's page requests, and destination backpressure stops reading ahead. CanopyX's source may retain identity/cursor bookkeeping for revision and duplicate detection; streamed document output does not imply constant memory for that entire source.
|
|
209
|
+
|
|
210
|
+
Host export callbacks can use the already-captured enumeration:
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import { writeCanopyTo } from "@evotecit/officeimo/integrations/canopyx";
|
|
214
|
+
import type { GridHostOptions } from "@evotecit/canopyx/reporting";
|
|
215
|
+
|
|
216
|
+
const onExport: GridHostOptions["onExport"] = async ({ capture, format, signal, reportProgress }) => {
|
|
217
|
+
if (format !== "xlsx" && format !== "csv" && format !== "pdf") {
|
|
218
|
+
throw new Error("Unsupported export format");
|
|
219
|
+
}
|
|
220
|
+
const destination = await openDestination(format); // Host-owned delivery.
|
|
221
|
+
await writeCanopyTo(capture, format, destination, {
|
|
222
|
+
...reportOptions, signal,
|
|
223
|
+
onProgress: progress => reportProgress?.("generating", progress.rows)
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
This entry exports grid records. Collapsed visual groups do not remove their records. The adapter exports records in the captured order; use the [grouped report writers](#grouped-analytical-reports) when an explicitly group-ordered capture needs summary rows and Excel outlines. Workers consume a host-owned bounded capture/row bridge; a live CanopyX grid remains on the page. Pass the writer's signal to the same capture enumeration and release the bridge when the host cancels it.
|
|
229
|
+
|
|
230
|
+
## PDF tables
|
|
231
|
+
|
|
232
|
+
`writePdf` and `writePdfTo` use the same `Column<T>` projection and `ExportCell` values as Excel and CSV. The PDF owner lays out and writes one page at a time, repeats grouped headings, splits oversized data rows across pages and appends a table footer. `writePdfTo` awaits the destination and retains page references, font mappings and the current page rather than the complete report body. Blob mode also retains the finished file.
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
import { writePdf, PdfFont, ExportCell, saveBlob } from "@evotecit/officeimo";
|
|
236
|
+
|
|
237
|
+
// Host-owned, embedding-permitted static TrueType font.
|
|
238
|
+
const response = await fetch("/fonts/report-regular.ttf");
|
|
239
|
+
if (!response.ok) throw new Error("Report font could not be loaded");
|
|
240
|
+
const regular = await PdfFont.create(new Uint8Array(await response.arrayBuffer()));
|
|
241
|
+
const report = await writePdf([
|
|
242
|
+
{ city: "Łódź", amount: 12.5 }, { city: "Gdańsk", amount: -2 }
|
|
243
|
+
], {
|
|
244
|
+
title: "Sales report", fonts: { regular },
|
|
245
|
+
columns: [
|
|
246
|
+
{ header: "City", key: "city", groups: ["Sales"] },
|
|
247
|
+
{ header: "Amount", key: "amount", groups: ["Sales"], alignment: "right",
|
|
248
|
+
value: row => new ExportCell(row.amount, {
|
|
249
|
+
text: row.amount.toFixed(2) + " USD",
|
|
250
|
+
presentation: row.amount < 0 ? { color: "9C0006", background: "FFC7CE" } : {}
|
|
251
|
+
}) }
|
|
252
|
+
],
|
|
253
|
+
footer: { values: ["Total"], totals: { amount: "sum" } },
|
|
254
|
+
pageFooter: "Confidential", pageSize: "A4", orientation: "portrait",
|
|
255
|
+
limits: { maxRows: 100_000, maxPages: 5_000, maxOutputBytes: 128_000_000 }
|
|
256
|
+
});
|
|
257
|
+
saveBlob(report, "sales.pdf");
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
PDF uses `ExportCell.text` first, then a synchronous `formatValue(value, context)` callback, then scalar text. Dates default to UTC ISO strings; null and nonfinite numbers are blank. Empty report titles, messages and page decorations are omitted without reserving space or consuming the cell/text budget. Excel number-format strings and live conditional rules are not evaluated by the PDF writer. Resolve display text and highlights in the shared getter or DataTables `project` callback when they must appear in both formats. Footer totals operate on typed numeric values and support `sum`, `count`, `average`, `min` and `max`.
|
|
261
|
+
|
|
262
|
+
Lengths are points, with 72 points per inch. Defaults are A4 portrait, 36-point margins, 9-point text, 4-point cell padding and page numbers. Named sizes are A3, A4, A5, LETTER, LEGAL and TABLOID; custom `{ width, height }` sizes are accepted. `columnWidths` supplies point widths; otherwise `Column.width` uses the width of the font's zero character. `wideTable: "fit"` fits column widths within the printable width while retaining font size and wrapping text. `"reject"` rejects widths that exceed the page. A column that cannot fit one glyph fails explicitly.
|
|
263
|
+
|
|
264
|
+
`Column.groups` provides simple grouped headings. `headerRows` replaces them with a rectangular `TableSpanRows` matrix: each anchor declares `{ value, columnSpan?, rowSpan? }`, and every covered position is `null`. `footer.rows` uses the same model instead of `footer.values`/`totals`. Matrices support up to 16 rows and must cover the declared columns without overlap. Repeated headings must leave space for data; a structured footer must fit below the headings on one page. Titles/messages, page headers/footers and final `Page N of M` labels are separate from the table. Message-only continuation pages retain page decorations without repeating table headings. Page decoration callbacks receive the [page and section context](#compose-a-pdf-report) and return a synchronous string. Page-number space is measured from the selected font and `maxPages`; for large fonts or narrow pages, reduce that limit or set `pageNumbers: false`. Table and paragraph heights respect the selected font face's ascent and descent.
|
|
265
|
+
|
|
266
|
+
Without supplied fonts, PDF uses standard Helvetica with WinAnsi text. For Polish, Greek, Cyrillic, CJK or other supported Unicode scalars, supply an embedding-permitted static TrueType font containing those glyphs. `PdfFont` copies and validates bytes once and can be reused. For cooperative parsing, use `await PdfFont.create(bytes, { signal, maxBytes })`; its default intake limit is 16 MiB and can be raised up to the constructor's 64 MiB ceiling. The source snapshot is taken before yielding, so later caller mutation cannot change the font. The synchronous constructor remains available. PDF finalization also cooperates with cancellation while building the glyph subset. Optional `bold`, `italic` and `boldItalic` faces preserve their real glyphs; missing faces use synthetic emphasis. Used glyphs and composite dependencies are embedded as a subset, with Unicode extraction maps. Font permissions can require full embedding or prohibit embedding, which fails visibly. Collections, CFF/WOFF and variable fonts require conversion to static TrueType before use. The library neither fetches fonts nor reads installed fonts; font licensing belongs to the host.
|
|
267
|
+
|
|
268
|
+
Call `preflightPdfText(text, { fonts: { regular }, bold: true })` from `@evotecit/officeimo/pdf` to check a known scalar-layout run before export. It returns `{ supported: true }` or the first issue with `code`, `message`, and a zero-based UTF-16 `index` in the original input; `scalar` identifies the original character and is absent for an unpaired surrogate. Codes distinguish `embedded-font-required`, `missing-glyph`, `unsupported-layout`, `unsupported-control` and `unpaired-surrogate`. The check uses scalar font selection, line-break and tab rules; it does not invoke an optional shaping provider. It checks only the supplied string, leaves row sources untouched, and does not establish wrapping, document resource limits or accessibility.
|
|
269
|
+
|
|
270
|
+
The default writer handles scalar text layout for Latin, Greek, Cyrillic, Han, Hiragana, Katakana, precomposed Hangul and common symbols, including supplementary Unicode where the font provides it. Keep a supplementary character in one rich-text run when its font, color or link metadata differs from adjacent text; splitting its UTF-16 pair across different presentation fails explicitly. If a supplied TrueType font lacks U+202F (narrow no-break space) but provides an inkless U+2009 (thin space), the writer uses that thin-space glyph and its advance while preserving U+202F in the PDF's Unicode map. Other missing glyphs and malformed surrogates fail explicitly. Combining sequences, bidirectional text and scripts requiring shaping need the optional profile below. It does not provide general HTML/SVG rendering or PDF/A. Composed documents support the bounded image and vector contracts below. Long text is wrapped and continued across pages without truncation; CRLF/CR become line breaks and tabs expand to four spaces for display.
|
|
271
|
+
|
|
272
|
+
`PdfLimits` includes shared row/cell/text/output ceilings plus `maxPages` (default 10,000), `maxColumns` (1,024), `maxCellCharacters` (1,000,000 UTF-16 units), `maxRowLines` (100,000), `maxFontBytes` (16 MiB across unique supplied fonts), `maxPageBytes` (8 MiB of drawing commands and link dictionaries), and `maxHyperlinks` (100,000 native annotations). A continued linked cell creates one annotation per page fragment; repeated linked headings also consume that limit. PDF cell/text budgets count rendered strings, headings, totals, bookmark titles and page decorations. Painted tabs count as four spaces; CR/LF separate lines without adding painted characters. The per-cell input ceiling still applies to the captured raw text. Captions count each painted occurrence; an unused continuation caption consumes no cell/text budget. `maxRows` counts source rows. Resource failures never silently remove rows, columns or text. With compression enabled and native deflate available, eligible streams are compressed and completed tagged structure objects share bounded containers. The first container is compressed to establish support; later containers store their bytes directly. This uses fewer native codec instances and produces larger files than compressing every container. Tagged compaction uses PDF 1.5 object/xref streams inside the existing PDF 1.7 document profile; supported readers must understand that representation. `compression: false` or unavailable native deflate retains plain objects and classic cross-references. Ordinary unit cells share immutable attribute objects within their table, retaining the same header identities in compressed and plain output. Object batches are bounded to 256 members and 32 KiB decoded bytes; page/object/font references and caller-owned output remain document-scale state.
|
|
273
|
+
|
|
274
|
+
Workers can call the same writers without a DOM. For a portable worker-to-page handoff, use `writePdfTo` and transfer byte chunks with acknowledgements; this also avoids WebKit worker Blob-read restrictions. Keep the row source and destination bridge bounded, and pass an `AbortSignal` to stop pending input or output. The caller owns disposal of partial bytes after failure, and the library releases borrowed stream locks without closing or aborting the destination.
|
|
275
|
+
|
|
276
|
+
### Readable wide tables
|
|
277
|
+
|
|
278
|
+
Use horizontal bands when an inventory has more columns than one page can display comfortably. The writer keeps each requested width instead of shrinking all columns to one page. Declare identifier columns to repeat at the left of every band:
|
|
279
|
+
|
|
280
|
+
```js
|
|
281
|
+
import { writePdf, saveBlob } from "@evotecit/officeimo";
|
|
282
|
+
|
|
283
|
+
const rows = [{ service: "WEB-000001", site: "Warsaw", owner: "Operations", environment: "Production",
|
|
284
|
+
availability: 99.98, latency: 4.9, errors: 0, cpu: 21, memory: 48, disk: 35, requests: 12340, checks: 120 }];
|
|
285
|
+
const columns = [
|
|
286
|
+
{ header: "Service", key: "service", rowHeader: true }, { header: "Site", key: "site" },
|
|
287
|
+
{ header: "Owner", key: "owner" }, { header: "Environment", key: "environment" },
|
|
288
|
+
{ header: "Availability %", key: "availability", type: "number" },
|
|
289
|
+
{ header: "Latency ms", key: "latency", type: "number" },
|
|
290
|
+
{ header: "Errors", key: "errors", type: "number" }, { header: "CPU %", key: "cpu", type: "number" },
|
|
291
|
+
{ header: "Memory %", key: "memory", type: "number" }, { header: "Disk %", key: "disk", type: "number" },
|
|
292
|
+
{ header: "Requests", key: "requests", type: "number" }, { header: "Checks", key: "checks", type: "number" }
|
|
293
|
+
];
|
|
294
|
+
const report = await writePdf(rows, {
|
|
295
|
+
columns,
|
|
296
|
+
tagged: { language: "en-US" },
|
|
297
|
+
wideTable: { mode: "bands", minimumColumnWidth: 90, repeatColumns: ["service", "site"] },
|
|
298
|
+
limits: { maxRows: 100_000, maxPages: 10_000, maxTableBands: 16, maxTableWindowRows: 128 }
|
|
299
|
+
});
|
|
300
|
+
saveBlob(report, "service-inventory.pdf");
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
`minimumColumnWidth` defaults to 72 points for inferred widths. Explicit `columnWidths` remain exact point widths. `repeatColumns` accepts exact stable column keys or zero-based positions in this table's captured selection. Numeric-only lists must be sorted and unique; string `"0"` is a key, while numeric `0` is a position. Mixed selections resolve to declared column order. Missing, ambiguous or duplicate targets reject before reading rows. Hidden fields and original grid positions are never consulted. If the identifiers and one further column cannot fit, the writer rejects the layout rather than clipping or shrinking it.
|
|
304
|
+
|
|
305
|
+
Each bounded record window is emitted through its bands before the next window. Long records share one logical fragment window while each band paints only the height its visible cells need. A continuation band with no remaining non-identifier content is omitted; initial rows, structured spans and link obligations are retained. Repeated identifier cells must fit below the repeated headings and group context on a fresh page; taller identifiers are rejected. A short final fragment retains the full identifier and enough row height to display it. Sources are consumed once, values and formatters are captured once, and numeric totals are accumulated once. Repeated headings, identifiers, links and page decorations still consume the document's physical output budgets. `maxTableBands` defaults to 64 per table; `maxTableWindowRows` defaults to 256 retained row fragments per window. These bounds do not imply constant memory for fonts, page references or caller-owned destinations.
|
|
306
|
+
|
|
307
|
+
The same `wideTable` option applies to `pdfTable`, `writeGroupedPdf` and `pdfGroupedTable`. Grouped tables add a leading label column: repeat `[0, "service"]` to retain that label and the selected service key, or `[0, 1]` for the label and first data position. Continued analytical bands retain the active ancestor context. A deliberately small `maxTableWindowRows` can separate the last detail and closing subtotals even when they would fit on one page; the retained-fragment bound takes precedence. Structured headings and footers preserve their intersecting span labels in each band. An indivisible footer span matrix must fit the window bound and the physical page. With `tagged: { language }`, physical bands share one logical table: cells follow source-column order within each source row, and repeated visual identifiers do not create duplicate logical text.
|
|
308
|
+
|
|
309
|
+
### Display language
|
|
310
|
+
|
|
311
|
+
PDF and CSV accept `booleanText: { true: "Tak", false: "Nie" }`; defaults remain `True`/`False`. Explicit `ExportCell.text` or a column/format callback takes precedence. These are display choices: native XLSX booleans remain boolean cells. CSV applies normal quoting, text limits and formula protection to custom labels.
|
|
312
|
+
|
|
313
|
+
PDF page counters accept `pageNumberLabels: { prefix: "Strona ", separator: " z ", suffix: "" }`. The default is `Page 1 of 3`. Labels are captured once and use the same font, geometry and text limits as the counter. Number/date formatting belongs to the host's explicit formatter or `ExportCell.text`; schema keys, Excel formulas and invariant defaults do not depend on translated headings or the machine's language.
|
|
314
|
+
|
|
315
|
+
### Compose a PDF report
|
|
316
|
+
|
|
317
|
+
`writePdfDocument` combines sections, paragraphs, lists, independently paginated tables, images, vector paths, portable drawings and explicit page breaks. `writePdfDocumentTo` writes the same blocks to a caller-owned destination. `pdfTable` checks each table's columns and getters against its row type.
|
|
318
|
+
|
|
319
|
+
```ts
|
|
320
|
+
import { writePdfDocument, pdfTable, saveBlob } from "@evotecit/officeimo";
|
|
321
|
+
import type { PdfDocumentBlock, PdfListItem } from "@evotecit/officeimo";
|
|
322
|
+
|
|
323
|
+
const columns = [
|
|
324
|
+
{ header: "Service", key: "service" },
|
|
325
|
+
{ header: "Owner", key: "owner" },
|
|
326
|
+
{ header: "Status", key: "status" },
|
|
327
|
+
{ header: "Latency (ms)", key: "latency", alignment: "right" }
|
|
328
|
+
] as const;
|
|
329
|
+
async function* findings(): AsyncGenerator<PdfListItem> {
|
|
330
|
+
yield { text: [{ text: "Review service latency. ", bold: true },
|
|
331
|
+
{ text: "Assign an owner and record the recovery action." }], keepTogether: true };
|
|
332
|
+
yield { text: "Retain this inventory as the baseline for the next review." };
|
|
333
|
+
}
|
|
334
|
+
async function* inventory() {
|
|
335
|
+
yield { service: "Directory", owner: "Operations", status: "Review", latency: 120 };
|
|
336
|
+
yield { service: "Resolver", owner: "Network", status: "Healthy", latency: 8 };
|
|
337
|
+
}
|
|
338
|
+
async function* blocks(): AsyncGenerator<PdfDocumentBlock> {
|
|
339
|
+
yield { kind: "section", title: "Service review", level: 1, headingStyle: "title" };
|
|
340
|
+
yield { kind: "paragraph", text: "Two services were checked.", style: "body" };
|
|
341
|
+
yield { kind: "paragraph", text: "Findings", headingLevel: 2, style: "heading",
|
|
342
|
+
bookmark: { title: "Findings", level: 2 } };
|
|
343
|
+
yield { kind: "list", ordered: true, itemStyle: "finding", items: findings() };
|
|
344
|
+
yield { kind: "vector", width: 120, height: 40, fill: "217346", commands: [
|
|
345
|
+
{ op: "move", x: 1, y: 39 }, { op: "line", x: 119, y: 39 },
|
|
346
|
+
{ op: "line", x: 119, y: 1 }, { op: "close" }
|
|
347
|
+
], alternativeText: "Illustrative rising service-health indicator.",
|
|
348
|
+
caption: { text: "Figure 1. Review indicator.", style: "caption" } };
|
|
349
|
+
yield { kind: "section", title: "Inventory appendix", level: 2,
|
|
350
|
+
headingStyle: "heading", orientation: "landscape" };
|
|
351
|
+
yield { ...pdfTable(inventory(), { columns }),
|
|
352
|
+
caption: { text: "Table 1. Checked services.", style: "caption" } };
|
|
353
|
+
// Omitted geometry restores the document's portrait defaults.
|
|
354
|
+
yield { kind: "section", title: "Next actions", level: 2, headingStyle: "heading" };
|
|
355
|
+
yield { kind: "list", itemStyle: "finding", items: [
|
|
356
|
+
{ text: "Assign each open finding to an owner.", keepTogether: true }
|
|
357
|
+
] };
|
|
358
|
+
}
|
|
359
|
+
const report = await writePdfDocument(blocks(), {
|
|
360
|
+
pageSize: "A4", orientation: "portrait", tagged: { language: "en" },
|
|
361
|
+
paragraphStyles: {
|
|
362
|
+
title: { fontSize: 20, presentation: { bold: true, color: "163C75" } },
|
|
363
|
+
heading: { fontSize: 14, presentation: { bold: true }, keepWithNext: true },
|
|
364
|
+
body: { fontSize: 10, spaceAfter: 10 },
|
|
365
|
+
finding: { fontSize: 10, spaceAfter: 8 },
|
|
366
|
+
caption: { fontSize: 9, presentation: { italic: true, color: "475569" } }
|
|
367
|
+
},
|
|
368
|
+
pageHeader: context => context.sectionTitle ?? "Service review",
|
|
369
|
+
pageFooter: context => `Section ${context.sectionNumber} / ${context.sectionPageNumber}`
|
|
370
|
+
});
|
|
371
|
+
saveBlob(report, "service-review.pdf");
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
Document options own fonts, padding, default page geometry, decorations and limits. Each table owns its columns, repeated headings, widths, presentation, formatter and totals. The existing font and supported-script rules apply to every block. `writePdf` and `writePdfTo` remain convenient entry points for one table. The [executable service report](../OfficeIMO.JavaScript.Examples/report-engine-job.mjs) shows the same composition over a caller-owned selected row source and summary metadata.
|
|
375
|
+
|
|
376
|
+
A `section` is a flat boundary for following blocks. Its `title` and optional `level` (1–6, default 1) supply a visible heading and native bookmark by default. `headingStyle` selects the heading's named appearance; `includeHeading: false` hides that heading and `bookmark: false` omits its outline entry. A boundary starts a fresh page after visible content; first or consecutive unpainted sections do not create blank transition pages. Each section derives omitted `pageSize`, `orientation`, `margins`, `pageHeader`, `pageFooter` and `pageNumbers` from the captured document defaults, rather than the preceding section. Page numbers remain continuous. Header/footer callbacks receive `pageNumber`, one-based `sectionNumber` and `sectionPageNumber`, and optional `sectionTitle`; they must return text synchronously. A paragraph's `bookmark: { title, level? }` follows its actual first painted line, including a heading moved by a keep rule.
|
|
377
|
+
|
|
378
|
+
`paragraphStyles` is a captured record of names to `fontSize`, `presentation` (`bold`, `italic`, text `color` and horizontal `alignment`), spacing and keep rules. Paragraph `style` selects one definition; explicit fields override it, and explicit presentation members merge with the named presentation. Styles have no inheritance and do not imply semantic headings: use `headingLevel` explicitly. Unknown names fail. The registry is shared across sections.
|
|
379
|
+
|
|
380
|
+
A `list` consumes synchronous or asynchronous `items` once. Each item has `text: PdfText`, optional `style` and `keepTogether`; its style replaces the list's `itemStyle` name. `ordered: true` uses decimal markers, with optional positive safe-integer `start`; otherwise it uses bullets. `start` is valid only for ordered lists. `indent` and `markerGap` are point lengths for hanging body text. The marker stays with the first body line and is not repeated on continuation pages. Nested lists and other nested blocks are unsupported; styles resolving to `keepWithNext: true` are rejected for items. An empty list adds no content or page break. An empty document still produces one PDF page; an explicit `pageBreak` remains a real page break.
|
|
381
|
+
|
|
382
|
+
Attach `caption: { text, style?, fontSize?, presentation?, spaceBefore?, spaceAfter? }` to a table, image, vector or drawing block. It appears before the owned content and stays with the first table heading/data fragment or the whole graphic. Captioned graphics require nonempty `alternativeText` and cannot be decorative, including in untagged output. Captions and kept content must fit together on a fresh page; reduce a graphic's display dimensions if necessary. Labels such as “Table 1” are authored text: automatic numbering, after-content captions and cross-references are unsupported.
|
|
383
|
+
|
|
384
|
+
The document-wide composition limits are `maxSections` (default 1,000), `maxBookmarks` (10,000), `maxListItems` (100,000) and `maxParagraphStyles` (256). They accept nonnegative safe integers and share the existing cumulative text, cell, page, font and output budgets. Section boundaries do not reset these budgets. Bookmark titles consume the text and cell budgets once as outline metadata, including when their visible heading is omitted.
|
|
385
|
+
|
|
386
|
+
Paragraph `text` can also be an array of `PdfTextRun` values. Each run supplies text and optional `bold`, `italic`, RGB `color`, an explicit `font` face or an HTTP(S)/mailto `link`. Wrapping preserves continuous text across run boundaries and gives each visible link fragment its own annotation:
|
|
387
|
+
|
|
388
|
+
```ts
|
|
389
|
+
const invoice = await writePdfDocument([
|
|
390
|
+
{ kind: "group", blocks: [
|
|
391
|
+
{ kind: "paragraph", text: "Invoice", headingLevel: 1, fontSize: 18 },
|
|
392
|
+
{ kind: "paragraph", text: [
|
|
393
|
+
{ text: "Customer: " }, { text: "Contoso", bold: true }
|
|
394
|
+
] }
|
|
395
|
+
] },
|
|
396
|
+
{ kind: "paragraph", keepTogether: true, spaceAfter: 12, text: [
|
|
397
|
+
{ text: "View the " },
|
|
398
|
+
{ text: "payment details", color: "0563C1", link: { target: "https://example.com/invoices/42" } }
|
|
399
|
+
] },
|
|
400
|
+
pdfTable([{ item: "Services", amount: 120 }], {
|
|
401
|
+
columns: [{ header: "Item", key: "item" }, { header: "Amount", key: "amount" }],
|
|
402
|
+
formatRuns: (value, cell) => [{
|
|
403
|
+
text: cell.columnIndex === 1 && typeof value === "number" ? value.toFixed(2) : String(value ?? ""),
|
|
404
|
+
bold: cell.columnIndex === 1
|
|
405
|
+
}]
|
|
406
|
+
})
|
|
407
|
+
], { fonts: { regular }, tagged: { language: "en-US" } });
|
|
408
|
+
saveBlob(invoice, "invoice.pdf");
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
`formatRuns(value, context)` is a synchronous PDF-only display callback for table data. It leaves raw values available to totals; `ExportCell.text`, including an explicit empty string, takes precedence. Whole-cell links and inline run links cannot overlap. The same static-font and supported-script rules apply to every run; styled text alone does not add shaping support. An explicit `font` is an exact `PdfFont` face. Bold/italic flags apply synthetic emphasis to that face; omit them when the supplied face already contains the desired emphasis. Distinct configured and explicit font identities share the document's `maxFontBytes` budget, including unused configured faces.
|
|
412
|
+
|
|
413
|
+
Paragraphs accept `keepTogether`, `keepWithNext`, `spaceBefore` and `spaceAfter`. Spacing defaults to zero points before and eight after. `keepTogether` moves an intact paragraph to a fresh page when needed; `keepWithNext` keeps it with the next visible paragraph line, first table fragment or complete graphic. A `group` contains paragraphs only and stays together by default. Nested groups and other block kinds are rejected; a final visible kept paragraph cannot reach outside its group. Content that cannot fit on a fresh page fails explicitly. `maxTextRuns` defaults to 10,000 per cell/paragraph and across a paragraph group or kept chain; `maxGroupBlocks` defaults to 256. Groups and kept chains also share `maxCellCharacters` so pagination cannot retain an unbounded report body.
|
|
414
|
+
|
|
415
|
+
Images accept `{ format: "png", data }`, `{ format: "jpeg", data }` or decoded `{ format: "rgb" | "rgba", width, height, data }` pixels. Raw pixels are row-major, 8 bits per channel, without row padding or premultiplied alpha. JPEG accepts 8-bit grayscale/RGB baseline, sequential and progressive frames. CMYK, ICC profiles, EXIF metadata and other component layouts fail explicitly; normalize color and orientation before supplying those JPEGs.
|
|
416
|
+
|
|
417
|
+
PNG intake accepts complete static, noninterlaced, 8-bit RGB/RGBA images with no color-profile metadata. It checks chunk CRCs, critical chunk order, scanline filters and the exact inflated byte length. RGB samples pass unchanged into the PDF's DeviceRGB image; straight alpha becomes a separate soft mask. Indexed/grayscale images, 16-bit samples, interlacing, animation, EXIF, `tRNS`, `sBIT`, and color/profile chunks (`sRGB`, `gAMA`, `cHRM`, `iCCP`, `cICP`, `mDCV`, `cLLI`) fail explicitly; normalize those inputs first. PNG decoding requires native `DecompressionStream("deflate")` and returns `code: "PLATFORM_UNAVAILABLE"` when unavailable. Arbitrary SVG bytes are not decoded.
|
|
418
|
+
|
|
419
|
+
An image's optional display `width` and `height` use points. One omitted dimension preserves the intrinsic aspect ratio; omitting both uses 96 DPI. The writer scales an oversized graphic down to the printable page and moves it intact to the next page when necessary. Source bytes are copied when the image is first consumed. Reusing that image object shares its PDF resource. Keep source objects and byte arrays stable until their block has been consumed.
|
|
420
|
+
|
|
421
|
+
Vector blocks use explicit top-left bounds and `move`, `line`, `cubic` and `close` commands. A block paints one path with optional six-digit RGB `fill` and `stroke`, `strokeWidth`, and `fillRule: "nonzero" | "evenodd"`. Coordinates must stay inside the declared bounds. Painting is clipped to those bounds. Images and vectors support `alignment: "left" | "center" | "right"`. This path contract does not interpret SVG markup, CSS, gradients, text or external resources.
|
|
422
|
+
|
|
423
|
+
Blocks and table rows are consumed once in order, with destination backpressure and cancellation. Pass a fresh source for each export. The result's `rows` sums the data rows across all tables; `columns` is the widest table. Row, cell, rendered-text, page, font, output and hyperlink limits cover the whole document. Graphics add `maxImageBytes` (32 MiB across distinct source image objects), `maxImagePixels` (16,777,216 pixels per image), and `maxVectorCommands` (100,000 commands across all vector blocks). Caller-owned destinations retain their normal partial-output and disposal contract.
|
|
424
|
+
|
|
425
|
+
Set optional `maxImageWorkingBytes` to reject an image before allocating its owned source snapshot, decoded planes and PNG scanlines. There is no default ceiling for this extra budget. PNG RGBA data is decoded directly into RGB and alpha planes with two scanlines; raw RGBA compacts its owned snapshot before writing the alpha mask. The budget excludes caller-owned input, finished output and native inflater/compressor allocations, so it does not bound total JavaScript heap or process memory. `maxImageBytes`, `maxImagePixels` and `maxOutputBytes` remain separate limits.
|
|
426
|
+
|
|
427
|
+
### Optional multilingual PDF shaping
|
|
428
|
+
|
|
429
|
+
The `@evotecit/officeimo/pdf/providers/harfbuzz` entry adapts host-loaded HarfBuzz and bidi engines. Importing it loads neither engine nor WASM. The default package and bundles retain no external runtime dependencies; applications choosing this profile install and load its engines explicitly:
|
|
430
|
+
|
|
431
|
+
```sh
|
|
432
|
+
npm install harfbuzzjs bidi-js
|
|
433
|
+
# TypeScript hosts also need the global type used by HarfBuzz's declarations:
|
|
434
|
+
npm install --save-dev @types/emscripten
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
```js
|
|
438
|
+
import * as harfbuzz from "harfbuzzjs";
|
|
439
|
+
import bidiFactory from "bidi-js";
|
|
440
|
+
import { PdfFont, writePdfDocument, saveBlob } from "@evotecit/officeimo/pdf";
|
|
441
|
+
import { createHarfBuzzTextShaper } from "@evotecit/officeimo/pdf/providers/harfbuzz";
|
|
442
|
+
|
|
443
|
+
async function loadFont(url) {
|
|
444
|
+
const response = await fetch(url);
|
|
445
|
+
if (!response.ok) throw new Error("Report font could not be loaded.");
|
|
446
|
+
return PdfFont.create(new Uint8Array(await response.arrayBuffer()));
|
|
447
|
+
}
|
|
448
|
+
const [latin, arabic] = await Promise.all([
|
|
449
|
+
loadFont("/fonts/Carlito-Regular.ttf"),
|
|
450
|
+
loadFont("/fonts/NotoSansArabic-Regular.ttf")
|
|
451
|
+
]);
|
|
452
|
+
const shaper = createHarfBuzzTextShaper({ harfbuzz, bidi: bidiFactory(), language: "ar" });
|
|
453
|
+
try {
|
|
454
|
+
const report = await writePdfDocument([{ kind: "paragraph", text: [
|
|
455
|
+
{ text: "Status: ", font: latin },
|
|
456
|
+
{ text: "السَّلَامُ عَلَيْكُمْ", font: arabic, color: "175F97" },
|
|
457
|
+
{ text: " (42)", font: latin }
|
|
458
|
+
] }], { fonts: { regular: latin }, textShaper: shaper, textDirection: "auto" });
|
|
459
|
+
saveBlob(report, "multilingual-report.pdf");
|
|
460
|
+
} finally { shaper.dispose(); }
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
The qualified adapter uses harfbuzzjs 1.6.3 and bidi-js 1.1.0, with a Unicode 13 repertoire of Latin, Arabic, common and inherited characters. It supports static TrueType faces, combining marks, Arabic joining and mixed-direction horizontal text in composed paragraphs and table cells. Supply fonts covering each run; no font discovery or fallback occurs. Other scripts, later Unicode repertoire, vertical text, variable/color fonts and general Unicode conformance are outside this profile. The provider's versioned character table carries its Unicode data license notice. Its engines remain separately loaded MIT-licensed packages. Browser hosts serve their ESM/WASM assets over HTTP(S) with the required CSP; the classic local-file assets do not bootstrap these engines.
|
|
464
|
+
|
|
465
|
+
Shaping sees the whole physical paragraph and reorders each finalized line using paragraph direction. The writer owns word/cluster wrapping, pagination, glyph embedding, CID/Unicode mappings, links and logical structure. `textDirection` accepts `auto`, `ltr` or `rtl`. A presentation, font or link boundary inside an indivisible cluster fails explicitly. Top-level `title`, `messageTop`/`messageBottom`, page decorations, portable drawing text and `preflightPdfText` use scalar layout; use composed paragraphs for shaped headings or messages.
|
|
466
|
+
|
|
467
|
+
Each shaped physical paragraph is limited to 4,096 UTF-16 units and each shaping call to 32,768 glyphs. One adapter caches at most 16 exact font identities. Cancellation runs between bounded synchronous WASM calls, and provider errors stop the export. `dispose()` drops strong font/buffer references and rejects later calls; HarfBuzz 1.6.3 releases native objects through finalizers, so deterministic WASM-heap release requires terminating the host-owned worker.
|
|
468
|
+
|
|
469
|
+
Logical source clusters are retained in `ToUnicode` and `ActualText`; tagged content allocates its structure references in logical order before visual painting. Independent native extractors can apply their own bidi ordering to raw text. Copy/paste order, screen-reader behavior and PDF/UA acceptance remain separate qualification. TypeScript host assignability is checked with bundler resolution and the engines' own declarations; bidi-js's CommonJS default declaration has a separate NodeNext interop limitation.
|
|
470
|
+
|
|
471
|
+
`PdfTextShaper` is the engine-independent replacement contract. It accepts exact registered fonts and logical UTF-16 ranges and returns positioned glyphs, without PDF commands or HarfBuzz types. The [owned text-engine roadmap](../Docs/ROADMAP.md#officeimo-owned-text-engines) scopes staged replacements behind that boundary.
|
|
472
|
+
|
|
473
|
+
### Portable drawings
|
|
474
|
+
|
|
475
|
+
A `drawing` block paints an ordered collection of paths, fixed-baseline text and rectangular clip groups as one indivisible graphic. It uses the same page fitting, alignment and tagged-figure alternatives as images and vectors. `OfficeIMO.Drawing.OfficeDrawingPortableExporter.TryExportJson` produces this wire format from supported `OfficeDrawing` content. Pass the parsed JSON as the block's `drawing` value; failed producer exports return diagnostics and no partial drawing.
|
|
476
|
+
|
|
477
|
+
```ts
|
|
478
|
+
import { writePdfDocument } from "@evotecit/officeimo";
|
|
479
|
+
import type { PdfDrawing } from "@evotecit/officeimo";
|
|
480
|
+
|
|
481
|
+
const drawing: PdfDrawing = {
|
|
482
|
+
version: 1, width: 200, height: 100,
|
|
483
|
+
elements: [
|
|
484
|
+
{ kind: "path", stroke: "555555", lineCap: "square", commands: [
|
|
485
|
+
{ op: "move", x: 10, y: 10 }, { op: "line", x: 10, y: 90 },
|
|
486
|
+
{ op: "line", x: 190, y: 90 }
|
|
487
|
+
] },
|
|
488
|
+
{ kind: "group", clip: { x: 10, y: 10, width: 180, height: 80 }, elements: [
|
|
489
|
+
{ kind: "path", stroke: "217346", strokeWidth: 2, lineJoin: "round", commands: [
|
|
490
|
+
{ op: "move", x: 0, y: 95 }, { op: "line", x: 80, y: 60 },
|
|
491
|
+
{ op: "line", x: 200, y: 15 }
|
|
492
|
+
] }
|
|
493
|
+
] }
|
|
494
|
+
]
|
|
495
|
+
};
|
|
496
|
+
const report = await writePdfDocument([
|
|
497
|
+
{ kind: "drawing", drawing, alternativeText: "Sales increased through the quarter.",
|
|
498
|
+
caption: { text: "Figure 1. Quarterly sales.", presentation: { italic: true } } }
|
|
499
|
+
], { tagged: { language: "en-US" } });
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
Version 1 accepts `path`, `text` and `group` elements only. Paths use the existing `move`, `line`, `cubic` and `close` commands, RGB fills/strokes, positive `strokeWidth`, `fillRule`, `lineCap: "butt" | "round" | "square"`, and `lineJoin: "miter" | "round" | "bevel"`. The miter limit is 10. Groups contain ordered `elements` and an optional rectangular `clip`. Every drawing is also clipped to its own bounds. Coordinates use points from the top left; finite values from -1,000,000 through 1,000,000 allow geometry to extend beyond a clip. Drawing dimensions are positive and at most 14,400 points; rectangular clip dimensions may reach 1,000,000 points.
|
|
503
|
+
|
|
504
|
+
Text elements declare `text`, `x`, `y`, `font`, `fontSize` and RGB `color`; `y` is the baseline. The font slot is `regular`, `bold`, `italic` or `boldItalic`, and that exact embedded static TrueType face must be supplied in the document's `fonts`. Use the same licensed static family in the .NET producer and the JavaScript writer. Missing faces and synthetic emphasis are rejected. Text stays at its authored position without wrapping or shaping; line breaks, control characters, unsupported scripts and missing glyphs fail explicitly under the existing scalar-text rules.
|
|
505
|
+
|
|
506
|
+
The wire format rejects unknown properties, versions, commands and element kinds. It does not parse SVG/CSS or load fonts and external resources. `maxDrawingElements` (default 100,000) counts paths, text and groups across drawing blocks; nesting is limited to 32 element levels. Drawing path commands share `maxVectorCommands` with vector blocks. Text shares cell/character budgets with the rest of the document. Serialized drawing content obeys `maxPageBytes`, and preflight and serialization cooperate with cancellation. Keep the supplied drawing stable until its block is consumed.
|
|
507
|
+
|
|
508
|
+
### Tagged PDF reports
|
|
509
|
+
|
|
510
|
+
Set `tagged: { language: "en-US" }` on a PDF writer to emit a logical structure tree. The language must be a locale identifier accepted by `Intl.getCanonicalLocales`. Composed paragraphs use `P` by default; `headingLevel: 1` through `6` selects `H1` through `H6` without changing the visual presentation. The document-level `title` uses `H1`; top/bottom messages use `P`.
|
|
511
|
+
|
|
512
|
+
Sections are `Sect` elements beneath one shared `Document`. Lists use `L` with ordered `LI` children, each containing a marker `Lbl` and a paragraph in `LBody`; a continued item retains that identity across pages. Captions are `Caption` children of their actual `Table` or `Figure`, before the owned content in reading order. Native bookmarks provide navigation destinations separately from these semantic roles.
|
|
513
|
+
|
|
514
|
+
```ts
|
|
515
|
+
import { writePdfDocument, pdfTable } from "@evotecit/officeimo";
|
|
516
|
+
|
|
517
|
+
const report = await writePdfDocument([
|
|
518
|
+
{ kind: "paragraph", text: "Sales report", headingLevel: 1,
|
|
519
|
+
fontSize: 18, presentation: { bold: true } },
|
|
520
|
+
{ kind: "paragraph", text: "Services sold this quarter." },
|
|
521
|
+
pdfTable([{ item: "Services", amount: 120 }], {
|
|
522
|
+
columns: [{ header: "Item", key: "item" }, { header: "Amount", key: "amount" }]
|
|
523
|
+
})
|
|
524
|
+
], { tagged: { language: "en-US" } });
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
Column headings use `TH` with column scope; empty heading cells use `TD`. Set `rowHeader: true` on a detail column to declare row-scope headings. Every ordinary cell references all declared headings in its row, including an identifier that follows a metric after column reordering. Multiple row headings are supported. This metadata does not select or physically repeat a column, infer roles from a caption, or change CSV/XLSX values and formatting. Column groups and `headerRows` preserve horizontal and vertical spans through `ColSpan`/`RowSpan`. Nonempty column headings have identifiers in the document's structure ID tree. Data and footer cells use explicit `Headers` associations to the applicable headings; a cell with no applicable heading has no such association. Structured `footer.rows` preserve their own spans. A table remains one `Table` with ordered `TR` and cell elements across pages and horizontal bands; each continued cell retains its logical identity. Repeated visual headings, identifiers, continuation captions, table borders/backgrounds, page headers/footers and page numbers are artifacts. Inline and whole-cell links use logical `Link` elements associated with their marked content and annotations across wrapping and page continuation; tagged links require a nonempty displayed label. Interactive links in artifact-only continuation captions have one logical alternative label while every visible copy retains its native annotation association.
|
|
528
|
+
|
|
529
|
+
`writeGroupedPdf` and composed `pdfGroupedTable` use nested group sections, visible group headings and native outline entries. Blank labels leave the section in place without an outline entry. `groupHeadingLevel` selects the first group's heading level (default 2); child groups increment it. Use 1 for a titleless report or 3 below an authored H2 section. A hierarchy extending beyond H6 is rejected. Each subtotal belongs to its own group and has an explicit row-heading label. A leaf subtotal shares its own detail table and header identities; an ancestor subtotal has a separate table under its ancestor section, and the grand total follows the groups. The last detail and leaf subtotal stay together when the physical page and retained-window limits permit. Labels and continuation text remain caller-authored; the engine never infers semantic roles from language, text prefixes or formatting.
|
|
530
|
+
|
|
531
|
+
Every image, vector or drawing block in tagged output requires either a nonempty `alternativeText` or `decorative: true`. Meaningful graphics become `Figure` elements with an alternative; decorative graphics are artifacts. Supplying both is an error. Figure alternatives count toward the cell/text budgets and obey `maxCellCharacters`. Choose alternatives and heading levels that express the report's meaning; the writer cannot infer them.
|
|
532
|
+
|
|
533
|
+
`maxStructureElements` (default 1,000,000) bounds the total logical elements created, including `Document`, sections, lists, captions, tables, rows, cells and figures. `maxMarkedContentReferences` (2,000,000) bounds the total references created for painted content, including continued cell lines. These cumulative limits include completed elements and apply across the document. Untagged output remains the default.
|
|
534
|
+
|
|
535
|
+
Selected reports were inspected in macOS Preview 11: tables, links and heading hierarchy were exposed, and group outline entries navigated to their destinations. In wide banded samples, the accessibility view exposed separate physical-page tables and fragmented repeated-heading text. These observations do not qualify logical table reading across bands, screen-reader speech or navigation.
|
|
536
|
+
|
|
537
|
+
This profile provides structure for supported reports. It does not claim accessible PDF or PDF/UA conformance. Assistive-technology behavior and author-supplied semantics require manual acceptance; see the [remaining accessibility work](../Docs/ROADMAP.md#officeimo-javascript).
|
|
538
|
+
|
|
539
|
+
## XLSX: workbook, worksheets and cells
|
|
540
|
+
|
|
541
|
+
```ts
|
|
542
|
+
import { Workbook, Cell, NumberFormats, saveBlob } from "@evotecit/officeimo/xlsx";
|
|
543
|
+
|
|
544
|
+
const workbook = new Workbook({ creator: "Report", dateMode: "utc" });
|
|
545
|
+
const highlighted = workbook.styles.add({
|
|
546
|
+
font: { bold: true, color: "123456" },
|
|
547
|
+
fill: { color: "D9E1F2" },
|
|
548
|
+
border: { bottom: { style: "thin", color: "123456" } },
|
|
549
|
+
numberFormat: NumberFormats.Decimal
|
|
550
|
+
});
|
|
551
|
+
const worksheet = workbook.addWorksheet("Controllers", {
|
|
552
|
+
columns: [
|
|
553
|
+
{ header: "Name", key: "name", width: 28 },
|
|
554
|
+
{ header: "Last seen", key: "seen", type: "date", format: "yyyy-mm-dd hh:mm" },
|
|
555
|
+
{ header: "Latency", key: "latency", type: "number", style: highlighted }
|
|
556
|
+
],
|
|
557
|
+
freezeHeader: true,
|
|
558
|
+
autoFilter: true
|
|
559
|
+
});
|
|
560
|
+
await worksheet.addRows([{ name: "DC01", seen: new Date(), latency: 12.5 }]);
|
|
561
|
+
await worksheet.addRows([["DC02", new Date(), new Cell(8, highlighted)]]);
|
|
562
|
+
saveBlob(await workbook.toBlob(), "controllers.xlsx");
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
Use `new Workbook(options)` and `addWorksheet(name, options)` for the advanced workbook API. `addWorksheet<RowType>` also accepts shared typed columns/getters and returns a `Worksheet<RowType>` whose `addRows` accepts that domain type. `workbook.worksheets` is a readonly snapshot. Each worksheet exposes its final sanitized `name` and data `rowCount`.
|
|
566
|
+
|
|
567
|
+
Rows can be synchronous or asynchronous iterables. Arrays are positional. Object rows use each column's literal `key`, or its `header` when no key is supplied; dots never traverse an object. Missing values produce empty cells and extra array values throw. Await each `addRows` call before appending to that worksheet or calling `toBlob`. A failed append prevents finalization. Repeated `toBlob` calls return the same output.
|
|
568
|
+
|
|
569
|
+
The public `StyleRegistry` owns fonts, fills, borders, number formats and cell-style indexes. `addFont`, `addFill`, `addBorder` and `addNumberFormat` register normalized definitions; `add` combines definitions or existing indexes. Equivalent definitions reuse their indexes. A column's `style` supplies a base, and `format`, `wrapText` and `alignment` override the corresponding fields. A `Cell` can select another registered style for a single value. Indexes belong to that workbook.
|
|
570
|
+
|
|
571
|
+
Cells accept strings, numbers, booleans, `Date`, `null` and `undefined`. Declared built-in types validate without coercion. Non-finite numbers and invalid dates become empty cells. Strings remain literal text, including `=...` and OOXML `_xHHHH_` sequences. XLSX never interprets a string as a formula.
|
|
572
|
+
|
|
573
|
+
Dates use Excel's 1900 system, including the fictitious leap day. `dateMode` defaults to local wall-clock fields; `"utc"` writes UTC clock fields. Cell dates carry no timezone. Property dates are UTC instants and are captured at construction. Valid cell date years are 1900 through 9999.
|
|
574
|
+
|
|
575
|
+
Excel limits are enforced: 1,048,576 rows including headings and the footer, 16,384 columns, 32,767 UTF-16 code units per cell, 65,530 hyperlinks per worksheet including oversized-text preservation links, 64,000 styles and widths from 0 through 255 characters. Names are trimmed, illegal characters become underscores, and names are shortened to 31 UTF-16 code units without splitting a surrogate pair. Blank names become `Sheet`, reserved `History` becomes `History_`, and case-insensitive duplicates receive a suffix.
|
|
576
|
+
|
|
577
|
+
`invalidCharacterPolicy` defaults to `"strip"`. XML 1.0-invalid controls, lone surrogates, U+FFFE and U+FFFF are removed. `"reject"` throws an `OfficeIMOError` with `code: "INVALID_XML"` for names, cell/header text, property text, font names and number formats. CR, LF, tabs, emoji, Polish and right-to-left text are preserved.
|
|
578
|
+
|
|
579
|
+
## Streamed output and resource limits
|
|
580
|
+
|
|
581
|
+
For one table, pass a native stream or `ByteSink` directly. The helper borrows the stream lock until it resolves or rejects; the caller closes or aborts the file and owns any partial bytes:
|
|
582
|
+
|
|
583
|
+
```ts
|
|
584
|
+
import { writeXlsxTo } from "@evotecit/officeimo";
|
|
585
|
+
|
|
586
|
+
async function exportSales(destination: WritableStream<Uint8Array>, signal: AbortSignal) {
|
|
587
|
+
const result = await writeXlsxTo(loadSales(), destination, {
|
|
588
|
+
columns, signal, dateMode: "utc",
|
|
589
|
+
limits: { maxRows: 1_000_000, maxCells: 8_000_000, maxOutputBytes: 512_000_000 },
|
|
590
|
+
onProgress: progress => console.log(progress.rows, progress.bytes)
|
|
591
|
+
});
|
|
592
|
+
// Close a file destination only after successful completion, using its host API.
|
|
593
|
+
return result;
|
|
594
|
+
}
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
`writeCsvTo` and `writePdfTo` have the same destination and completion contract. Pass the signal into paged fetching and destination I/O too; rejecting an export does not cancel application-owned I/O automatically. Native Web Streams need no adapter and receive owned chunks that their underlying sink may retain. For Node writable streams, use the platform's `Writable.toWeb` adapter as shown below.
|
|
598
|
+
|
|
599
|
+
Select a caller-owned sink when constructing the workbook to deliver ZIP bytes during row production. Complete streamed worksheets in order: `close()` completes a worksheet explicitly, and starting the next worksheet closes its predecessor. Await each append before switching worksheets. A closed worksheet cannot receive more rows. `finish()` completes the ZIP directory and returns data-row, sheet and byte counts; repeated calls reuse the same result. The row count excludes headings, footers and preservation-sheet records. The sheet count includes the preservation sheet when present.
|
|
600
|
+
|
|
601
|
+
```ts
|
|
602
|
+
import { Workbook } from "@evotecit/officeimo/xlsx";
|
|
603
|
+
import type { Rows } from "@evotecit/officeimo/core";
|
|
604
|
+
|
|
605
|
+
async function exportRows(rows: Rows, destination: WritableStream<Uint8Array>) {
|
|
606
|
+
const writer = destination.getWriter();
|
|
607
|
+
try {
|
|
608
|
+
const book = new Workbook({
|
|
609
|
+
sink: { write: bytes => writer.write(bytes) }, dateMode: "utc",
|
|
610
|
+
limits: { maxRows: 1_000_000, maxCells: 8_000_000, maxOutputBytes: 512_000_000 }
|
|
611
|
+
});
|
|
612
|
+
const sheet = book.addWorksheet("Data", {
|
|
613
|
+
columns: [{ header: "Name", key: "name" }, { header: "Amount", key: "amount", type: "number", format: "0.00" }]
|
|
614
|
+
});
|
|
615
|
+
await sheet.addRows(rows);
|
|
616
|
+
const result = await book.finish();
|
|
617
|
+
await writer.close();
|
|
618
|
+
return result;
|
|
619
|
+
} catch (error) {
|
|
620
|
+
await writer.abort(error).catch(() => {});
|
|
621
|
+
throw error;
|
|
622
|
+
} finally { writer.releaseLock(); }
|
|
623
|
+
}
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
The library awaits byte acceptance and never closes a supplied sink. The destination owns cancellation and disposal of partial output. Use the same signal for the writer, paged source and destination I/O. `toBlob()` remains the default output path and supports interleaved appends to different worksheets; it retains compressed output proportional to file size. A workbook with a caller-owned sink uses `finish()` instead of `toBlob()`.
|
|
627
|
+
|
|
628
|
+
Both CSV and XLSX accept optional `limits`: `maxRows` counts data rows per worksheet/export, including generated preservation rows; `maxCells` counts emitted cells, including titles, headings, footers and preservation records. `maxTextCharacters` counts UTF-16 units of string values, including CSV formatter/display/null-text results and XLSX titles, headings, footers, previews and full preservation records. Numeric/date encodings, CSV quoting and XML markup do not count toward that text limit. `maxOutputBytes` limits actual UTF-8 CSV or ZIP bytes accepted by the sink and also bounds compressed worksheet retention in Blob mode. XLSX also accepts `maxStyles`, `maxSheets`, `maxHyperlinks`, `maxImageBytes` and `maxMergedRanges`. The merge limit defaults to 10,000 across all worksheets, including generated title/group merges. Cell/text budgets are checked at row ingress, reserving generated cells/text before retaining input. Exceeding a ceiling throws `OfficeIMOError` with `code: "RESOURCE_LIMIT"`. Limits are nonnegative safe integers; `maxStyles` is from 1 through 64,000. No host-dependent timing or heap threshold is enforced by the library.
|
|
629
|
+
|
|
630
|
+
Native XLSX charts add workbook-wide `maxCharts` (100 by default), `maxChartPoints` (100,000 numeric values across all series) and `maxChartTextCharacters` (1,000,000 UTF-16 units across chart metadata and category/series labels). Each chart's hidden source worksheet also counts toward `maxSheets`, and its cells obey the normal row, cell, text and output limits.
|
|
631
|
+
|
|
632
|
+
XLSX rejects oversized text by default. Set `oversizedText: "preserve"` to write a bounded preview with an internal link to the full value on a `Text overflow` worksheet. Each overflow record identifies the source sheet/cell, one-based part number, text and total part count. Concatenate its `Text` values in part order to reconstruct the complete XML-valid value. Chunks never split a supplementary Unicode character. The same strip/reject policy applies to invalid XML characters. Preserve mode does not replace an existing external link on that cell; that conflict throws.
|
|
633
|
+
|
|
634
|
+
ZIP entries cannot interleave, so preservation retains a bounded text spool until the report worksheets finish. `maxOverflowCharacters` defaults to 4,000,000 UTF-16 units. Width sampling has separate defaults of 100,000 retained cells and 1,000,000 UTF-16 units of encoded row XML, including markup, configurable through `maxBufferedCells` and `maxBufferedCharacters`. Automatic width sampling stops within these budgets; an explicitly requested sample that exceeds them fails visibly. Full cell values are preserved in both cases. CSV retains long text directly and is an alternative when Excel's cell/storage constraints do not suit the data.
|
|
635
|
+
|
|
636
|
+
### Node writable streams
|
|
637
|
+
|
|
638
|
+
`Writable.toWeb` connects Node file or HTTP response streams to `writeXlsxTo`, `writeCsvTo` and `writePdfTo`, including backpressure. End the Node stream after a successful export and await `finished` before using the file. Destroy it on failure; the caller decides whether to remove a partial file.
|
|
639
|
+
|
|
640
|
+
```ts
|
|
641
|
+
import { createWriteStream } from "node:fs";
|
|
642
|
+
import { Writable } from "node:stream";
|
|
643
|
+
import { finished } from "node:stream/promises";
|
|
644
|
+
import { writeXlsxTo } from "@evotecit/officeimo";
|
|
645
|
+
|
|
646
|
+
async function exportSales(path: string, signal: AbortSignal) {
|
|
647
|
+
const output = createWriteStream(path, { signal });
|
|
648
|
+
const completion = finished(output);
|
|
649
|
+
void completion.catch(() => {}); // Observe I/O failures while the exporter is still writing.
|
|
650
|
+
try {
|
|
651
|
+
const result = await writeXlsxTo([{ customer: "Contoso", amount: 12.5 }], Writable.toWeb(output), {
|
|
652
|
+
columns: [{ header: "Customer", key: "customer" }, { header: "Amount", key: "amount" }], signal
|
|
653
|
+
});
|
|
654
|
+
output.end();
|
|
655
|
+
await completion;
|
|
656
|
+
return result;
|
|
657
|
+
} catch (error) {
|
|
658
|
+
output.destroy();
|
|
659
|
+
await completion.catch(() => {});
|
|
660
|
+
throw error;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
## Workers and paged sources
|
|
666
|
+
|
|
667
|
+
Use `@evotecit/officeimo/execution` to send projected rows to an application-owned worker. The page keeps its grid and source I/O; the worker calls the normal format writer. `ExportCell` values retain their typed value, display text, presentation and links across the handoff, and Dates remain Dates.
|
|
668
|
+
|
|
669
|
+
The page creates the worker and owns its lifetime:
|
|
670
|
+
|
|
671
|
+
```ts
|
|
672
|
+
import { executeWorkerExport } from "@evotecit/officeimo/execution";
|
|
673
|
+
import { BlobByteSink } from "@evotecit/officeimo/core";
|
|
674
|
+
import { saveBlob } from "@evotecit/officeimo";
|
|
675
|
+
|
|
676
|
+
const worker = new Worker(new URL("./report.worker.js", import.meta.url), { type: "module" });
|
|
677
|
+
const controller = new AbortController();
|
|
678
|
+
const sink = new BlobByteSink();
|
|
679
|
+
try {
|
|
680
|
+
await executeWorkerExport(worker, [["Contoso", 12.5]], sink, {
|
|
681
|
+
signal: controller.signal,
|
|
682
|
+
input: { columns: [{ header: "Customer" }, { header: "Amount", type: "number" }] }
|
|
683
|
+
});
|
|
684
|
+
saveBlob(sink.toBlob("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"), "sales.xlsx");
|
|
685
|
+
} catch (error) {
|
|
686
|
+
sink.discard();
|
|
687
|
+
throw error;
|
|
688
|
+
} finally {
|
|
689
|
+
worker.terminate();
|
|
690
|
+
}
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
The worker installs its chosen operation. Keep application callbacks here; functions cannot cross the messaging boundary:
|
|
694
|
+
|
|
695
|
+
```ts
|
|
696
|
+
// report.worker.ts
|
|
697
|
+
import { handleWorkerExports } from "@evotecit/officeimo/execution";
|
|
698
|
+
import { writeXlsxTo } from "@evotecit/officeimo";
|
|
699
|
+
import type { Column, ExportValue } from "@evotecit/officeimo";
|
|
700
|
+
|
|
701
|
+
const handler = handleWorkerExports(self, ({ input, rows, sink, signal, onProgress }) => {
|
|
702
|
+
const options = input as { columns: readonly Column<readonly ExportValue[]>[] };
|
|
703
|
+
return writeXlsxTo(rows, sink, { columns: options.columns, signal, onProgress });
|
|
704
|
+
});
|
|
705
|
+
// Call handler.dispose() if this worker stops accepting exports but remains alive.
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
`executeWorkerExport` returns `{ rows, columns, bytes }` and accepts a `ByteSink` or `WritableStream<Uint8Array>`. Use a destination rather than `BlobByteSink` when the completed file should not stay in memory. The worker operation can call CSV or PDF writers in the same way. One endpoint accepts one export at a time and can be reused after completion, failure or cancellation.
|
|
709
|
+
|
|
710
|
+
The default handoff sends at most 64 rows and 65,536 selected cells per batch, with 1,000,000 UTF-16 units across values, display text, links and presentation strings. `batchRows`, `maxBatchCells` and `maxBatchCharacters` change these ceilings; one row must fit. Cell/text budgets can leave one captured lookahead row on the host. Output sends one chunk of at most 65,536 bytes at a time, controlled by `maxChunkBytes`, and awaits the destination before acknowledging it. Progress coalesces while an acknowledgement is pending and preserves its final update. These are message bounds, not a whole-process memory guarantee.
|
|
711
|
+
|
|
712
|
+
`input` accepts plain records, arrays, Dates and `Uint8Array` bytes, with default `maxSetupBytes` of 16 MiB, `maxSetupNodes` of 100,000 and nesting up to 32 levels. The byte budget counts UTF-16 string storage and binary bytes. Functions, accessors, cycles, live grid objects and `PdfFont` instances are rejected. Send font bytes when needed and reconstruct them with `await PdfFont.create(bytes, { signal })` inside the operation. Configuration and row/output data are copied through structured cloning; caller-owned buffers are never detached.
|
|
713
|
+
|
|
714
|
+
Pass an `AbortSignal` to the handoff and the same signal to host-owned page fetching and destination I/O. Cancellation rejects pending source/sink requests, invokes producer cleanup and removes transport listeners. The destination owns partial output. `handler.dispose()` cancels its active operation and removes its listeners; the host still owns worker termination and any object URL it created. Remote OfficeIMO errors retain their `code` and unsupported-feature identifier; a host callback failure or host cancellation preserves its original local reason.
|
|
715
|
+
|
|
716
|
+
`createDataTablesExport(...).rows` and `createCanopyExport(...).rows()` already produce portable array rows. Supply those rows and their captured columns to the handoff while leaving selection, paging, revisions and source disposal with the owning integration. For an application API, yield pages from an async generator and convert JSON date strings before yielding. Getters that select domain fields run before the worker handoff, or are defined in the worker with its own source. The [worker qualification](../Build/BrowserExports/execution-contracts.js) exercises classic and module workers, backpressure, cancellation and disposal in Chromium, Firefox and WebKit.
|
|
717
|
+
|
|
718
|
+
The table helpers and DataTables adapter own their workbook. Use portable `ExportCell` values and style definitions in report patches. Workbook-local column/header style IDs, numeric font/fill/border/format references and advanced `Cell` values require the `Workbook` API, where the caller can register those definitions. The convenience writers reject them instead of interpreting indexes from another workbook. Use `XlsxColumn<T>` for advanced columns with a registered style or `Cell` keys/getter results; `Column<T>` is the portable projection shared with CSV. Literal keys select scalar, nullable, date or `ExportCell` fields. Nested objects or arrays need explicit scalar getters for each selected column.
|
|
719
|
+
|
|
720
|
+
## Resolved values, grouped headings, totals and print layout
|
|
721
|
+
|
|
722
|
+
`ExportCell` captures a typed value, optional display text and portable presentation before an export begins. Presentation accepts the declared scalar fields only: string colors/number formats, Boolean emphasis/wrapping flags and supported alignment values. Invalid field types are rejected; undeclared fields are omitted. A report producer can resolve highlighting once and reuse the same cells for XLSX, CSV and PDF. XLSX uses the typed value; CSV uses it by default and uses supplied display text with `valueMode: "display"`. PDF prefers supplied display text and applies portable presentation. Formula protection and quoting still run after display-text selection and CSV formatting.
|
|
723
|
+
|
|
724
|
+
```ts
|
|
725
|
+
import { Workbook, ExportCell } from "@evotecit/officeimo/xlsx";
|
|
726
|
+
import { writeCsv } from "@evotecit/officeimo/csv";
|
|
727
|
+
|
|
728
|
+
const columns = [
|
|
729
|
+
{ header: "Name", key: "name", groups: ["Identity"], width: 28 },
|
|
730
|
+
{ header: "Latency", key: "latency", groups: ["Metrics"], type: "number", format: "0.000" }
|
|
731
|
+
] as const;
|
|
732
|
+
const rows = [{ name: "Łódź", latency: new ExportCell(125.75, {
|
|
733
|
+
text: "125.750 ms", presentation: { background: "FCE4D6", bold: true }
|
|
734
|
+
}) }];
|
|
735
|
+
const book = new Workbook();
|
|
736
|
+
const sheet = book.addWorksheet("Report", {
|
|
737
|
+
title: { text: "Controller health", style: { font: { size: 20 }, fill: { color: "D9E1F2" } }, height: 32 },
|
|
738
|
+
columns, table: { name: "ReportData" }, freezeHeader: true,
|
|
739
|
+
autoSize: { sampleRows: 100, minWidth: 8, maxWidth: 40 },
|
|
740
|
+
footer: { values: ["Totals"], totals: { latency: "average" }, style: { font: { bold: true } } },
|
|
741
|
+
print: { paper: "A4", orientation: "landscape", repeatHeaders: true, header: "Health report", footer: "Measured latency" }
|
|
742
|
+
});
|
|
743
|
+
await sheet.addRows(rows);
|
|
744
|
+
const excel = await book.toBlob();
|
|
745
|
+
const csv = await writeCsv(rows, { columns, valueMode: "display" });
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
Portable presentation supports background/text color, bold, italic, wrapping, alignment and number format. It overlays the resolved row/cell presentation while preserving unspecified fields; an explicit workbook-local `Cell.style` retains precedence. CSV carries scalar values/display text; it has no cell-style format.
|
|
749
|
+
|
|
750
|
+
`title` adds one merged row above the headings. Its default font is bold, 18 points, with a 28-point row height; `style` composes a normal `CellStyle` patch and `height` overrides the row height. Titles use literal XML-valid text of at most 32,767 UTF-16 units. Contiguous column `groups` with matching ancestor labels form merged heading spans above the leaf headers, with at most 16 levels. Native tables start at the leaf-header row, and `freezeHeader` freezes the title and all heading rows. Style callback row numbers, explicit hyperlink/image anchors and merge ranges use the final worksheet coordinates, including the title.
|
|
751
|
+
|
|
752
|
+
`mergedCells: ["A1:B2", "A3:B3"]` merges explicit uppercase A1 ranges. Each range must contain at least two cells, stay within the declared columns and rows actually exported, and avoid other merges, including generated title/group merges. A native table cannot contain merged cells. The top-left cell retains its value and presentation; covered cells must contain null/undefined or an empty string, and cannot carry hyperlinks or computed totals. A nonempty covered value throws instead of being silently lost. Use `includeHeader: false` for a free-form region without leaf headings:
|
|
753
|
+
|
|
754
|
+
```ts
|
|
755
|
+
const regions = book.addWorksheet("Summary", {
|
|
756
|
+
columns: [{ header: "A" }, { header: "B" }], includeHeader: false,
|
|
757
|
+
mergedCells: ["A1:B2", "A3:B3"]
|
|
758
|
+
});
|
|
759
|
+
await regions.addRows([["Report summary", null], [null, null], ["End", null]]);
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
`sheet.headerRows` replaces inferred group/leaf headings with a rectangular `TableSpanRows` matrix. Each anchor carries a typed `value` and optional `columnSpan`/`rowSpan`; covered positions are `null`. `sheet.footer.rows` uses the same shape after the data and is mutually exclusive with `footer.values`/`footer.totals`. Both matrices are captured before consuming the source. Heading/footer rows do not increase data-row progress or completion counts. `includeHeader: false` suppresses replacement headings too.
|
|
763
|
+
|
|
764
|
+
```ts
|
|
765
|
+
const columns = [{ header: "ID" }, { header: "Asset" }, { header: "State" }, { header: "Score", type: "number" }] as const;
|
|
766
|
+
const headerRows = [
|
|
767
|
+
[{ value: "Identity", columnSpan: 2 }, null, { value: "Assessment", columnSpan: 2 }, null],
|
|
768
|
+
columns.map(column => ({ value: column.header }))
|
|
769
|
+
];
|
|
770
|
+
const footerRows = [
|
|
771
|
+
[{ value: "Source", rowSpan: 2 }, { value: "Operational snapshot", columnSpan: 3 }, null, null],
|
|
772
|
+
[null, { value: "Owner reviewed", columnSpan: 3 }, null, null]
|
|
773
|
+
];
|
|
774
|
+
const book = new Workbook();
|
|
775
|
+
const sheet = book.addWorksheet("Assessment", {
|
|
776
|
+
columns, headerRows, footer: { rows: footerRows }, table: {}, freezeHeader: true
|
|
777
|
+
});
|
|
778
|
+
await sheet.addRows([["0001", "Controller", "Healthy", 99.3]]);
|
|
779
|
+
const workbook = await book.finish();
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
The final heading row above is unmerged and matches the leaf labels, so a native table/filter can use it. Other rectangular headings are supported when table/filtering is disabled. Explicit span matrices retain separate adjacent groups even when their labels are equal.
|
|
783
|
+
|
|
784
|
+
`footer.values` supplies explicit typed footer cells in column order. `footer.totals` maps unambiguous column keys (or headers without keys) to `sum`, `count`, `average`, `min` or `max`. Aggregation uses visible finite numbers written to Excel, including converted date serials and column-writer results; manually hidden rows and cells containing nested `SUBTOTAL` or `AGGREGATE` functions are excluded. The writer retains only the state needed by each column's operation. Count means numeric count and uses General format rather than a column's date format. Formulas use `SUBTOTAL`, with cached values for readers; averages/minima/maxima remain blank when no visible numeric value exists, including when filtering hides every numeric row. Their guarded expressions are registered as custom table totals so native Excel sees consistent formula metadata. Totals respond to Excel filtering; strings supplied as ordinary values never become formulas. A sum outside JavaScript's finite numeric range fails visibly.
|
|
785
|
+
|
|
786
|
+
`autoSize` inspects a leading sample of up to 100 rows by default, then starts the worksheet. Automatic sampling shortens the sample to fit the cell and encoded-text buffer budgets, including on wide tables. An explicit `sampleRows` can reach Excel's row capacity and fails if the sample exceeds a buffer budget. Inspecting a complete table requires enough `maxBufferedCells` and `maxBufferedCharacters` capacity for its serialized rows; keep the default leading sample when early streamed output and bounded memory matter. Sampling can span append calls. Each sampled row is validated and serialized once; custom value/style callbacks do not run again when the sample is written. Widths use an approximate character count, preferring `ExportCell.text`, clamped to `minWidth`/`maxWidth`; column `width` wins. This is bounded sizing rather than font measurement.
|
|
787
|
+
|
|
788
|
+
`print` sets A4/Letter paper, portrait/landscape orientation, fit-to-page dimensions and inch-based margins. Defaults are A4, landscape, one page wide and unlimited pages high. Print area includes the title, headings, data and footer; `repeatHeaders` repeats grouped/leaf headings and leaves the report title on its first page. Center header/footer strings are literal text: ampersands are protected from Excel control-code interpretation.
|
|
789
|
+
|
|
790
|
+
## Report tables, highlighting and images
|
|
791
|
+
|
|
792
|
+
Use worksheet presentation options to carry a report's highlights into Excel while retaining typed values and column number formats:
|
|
793
|
+
|
|
794
|
+
```ts
|
|
795
|
+
import { Workbook, NumberFormats, saveBlob } from "@evotecit/officeimo/xlsx";
|
|
796
|
+
|
|
797
|
+
const book = new Workbook({ creator: "Health report", dateMode: "utc" });
|
|
798
|
+
const headerStyle = book.styles.add({
|
|
799
|
+
font: { bold: true, color: "FFFFFF" }, fill: { color: "203864" },
|
|
800
|
+
verticalAlignment: "center", wrapText: true
|
|
801
|
+
});
|
|
802
|
+
const sheet = book.addWorksheet("Controllers", {
|
|
803
|
+
columns: [
|
|
804
|
+
{ header: "Name", key: "name", width: 28 },
|
|
805
|
+
{ header: "Latency", key: "latency", type: "number", format: "0.000" },
|
|
806
|
+
{ header: "Seen", key: "seen", type: "date", format: NumberFormats.DateTime },
|
|
807
|
+
{ header: "Healthy", key: "healthy", type: "boolean" }
|
|
808
|
+
],
|
|
809
|
+
table: { name: "Controllers", style: "TableStyleMedium9" },
|
|
810
|
+
headerStyle, headerHeight: 30, rowHeight: 24,
|
|
811
|
+
freezeHeader: true, freezeColumns: 1,
|
|
812
|
+
alternatingRowStyle: { fill: { color: "EAF1F8" } },
|
|
813
|
+
rowStyle: ({ values }) => values[3] === false
|
|
814
|
+
? { fill: { color: "FCE4D6" }, font: { bold: true } } : undefined,
|
|
815
|
+
cellStyle: ({ value, columnIndex }) => columnIndex === 1 && typeof value === "number" && value > 100
|
|
816
|
+
? { font: { color: "C00000" } } : undefined
|
|
817
|
+
});
|
|
818
|
+
await sheet.addRows([
|
|
819
|
+
{ name: "Łódź", latency: 125.75, seen: new Date("2026-10-06T12:00:00Z"), healthy: false }
|
|
820
|
+
]);
|
|
821
|
+
sheet.addHyperlink({ cell: "A2", target: "https://example.com/report", tooltip: "Open report" });
|
|
822
|
+
saveBlob(await book.toBlob(), "health-report.xlsx");
|
|
823
|
+
```
|
|
824
|
+
|
|
825
|
+
`table` writes a native Excel table with filtering and a built-in `TableStyleLight1..21`, `TableStyleMedium1..28` or `TableStyleDark1..11` style. Row banding defaults to true; `bandedColumns`, `firstColumn` and `lastColumn` control other table accents. Names are workbook-unique ASCII identifiers, at most 255 characters, and cannot be cell references. Omitted names are generated. Table headers must be nonblank, unique ignoring case and at most 255 characters. An empty export writes the headers without creating a table or an artificial data row.
|
|
826
|
+
|
|
827
|
+
Styles apply in this order: column style/format, alternating-row patch, row patch, then cell patch. A `Cell` with an explicit style replaces the column/alternating/row presentation; the cell callback can still overlay it. `StyleRegistry.compose(base, patch)` exposes the same composition. Font fields and border edges merge; numeric font/fill/border indexes replace their component. Unspecified number formats, wrapping and alignment remain intact. Fonts support bold, italic, underline and strike; `verticalAlignment` complements horizontal `alignment`.
|
|
828
|
+
|
|
829
|
+
Style callbacks are synchronous. Their `rowIndex` and `columnIndex` are zero-based data indexes. `worksheetRow` is the one-based Excel row, including titles and headings. Row `values` follow the declared export order and unwrap `Cell` values. A cell callback sees the value after a custom column writer. Headers use `headerStyle` separately. Alternating patches start on the second data row and remain consistent across appends. Heights are points, positive and at most 409; `freezeColumns` freezes leading columns alongside an optional header.
|
|
830
|
+
|
|
831
|
+
Native tables default unspecified column widths to 20 characters so date/time and numeric columns have useful space. Set `defaultColumnWidth` for another fallback or a column's `width` for an individual override. Worksheets without a table retain Excel's default width unless a width is supplied. These are fixed widths, not font-measured autofit.
|
|
832
|
+
|
|
833
|
+
Hyperlinks can also be supplied through `SheetOptions.hyperlinks`. Each link addresses one exported cell and uses an absolute HTTP, HTTPS or mailto URL. HTTP credentials, unsafe schemes and duplicate link cells are rejected. Links preserve the existing cell value and style; use a style patch for blue/underlined link text when desired.
|
|
834
|
+
|
|
835
|
+
`sheet.addImage({ data: pngBytes, row: 6, column: 1, width: 640, height: 320, description: "Latency chart" })` places a PNG, such as a rendered chart, without changing table data. Supply a `Uint8Array` containing the complete PNG; the library checks its signature/IHDR and copies the bytes. Anchors are one-based; display dimensions are CSS pixels at 96 DPI. The writer embeds the image and a one-cell drawing anchor. It does not render charts or convert SVG. Multiple worksheets can each contain a table, links and images.
|
|
836
|
+
|
|
837
|
+
## Native editable Excel charts
|
|
838
|
+
|
|
839
|
+
`sheet.addChart` writes a native Excel chart with editable source cells, cached values, labels and axes. Choose `columnClustered`, `barClustered`, `line` or `pie`. PNGs supplied through `addImage` retain their rendered appearance; native charts use Excel's chart drawing and editing. PDF reports can use the [portable drawing contract](#portable-drawings) for already composed graphics.
|
|
840
|
+
|
|
841
|
+
```ts
|
|
842
|
+
import { Workbook, saveBlob } from "@evotecit/officeimo/xlsx";
|
|
843
|
+
|
|
844
|
+
const rows = [
|
|
845
|
+
{ site: "Łódź", actual: 12.5, target: 15 },
|
|
846
|
+
{ site: "Warsaw", actual: 25, target: 15 },
|
|
847
|
+
{ site: "Gdańsk", actual: 8, target: 15 }
|
|
848
|
+
];
|
|
849
|
+
const book = new Workbook();
|
|
850
|
+
const sheet = book.addWorksheet("Controllers", {
|
|
851
|
+
columns: [
|
|
852
|
+
{ header: "Site", key: "site" },
|
|
853
|
+
{ header: "Actual", key: "actual", type: "number" },
|
|
854
|
+
{ header: "Target", key: "target", type: "number" }
|
|
855
|
+
],
|
|
856
|
+
table: {}
|
|
857
|
+
});
|
|
858
|
+
await sheet.addRows(rows);
|
|
859
|
+
sheet.addChart({
|
|
860
|
+
type: "columnClustered", title: "Controllers by site",
|
|
861
|
+
data: {
|
|
862
|
+
categories: rows.map(row => row.site),
|
|
863
|
+
series: [
|
|
864
|
+
{ name: "Actual", values: rows.map(row => row.actual), color: "2563EB" },
|
|
865
|
+
{ name: "Target", values: rows.map(row => row.target), color: "94A3B8" }
|
|
866
|
+
]
|
|
867
|
+
},
|
|
868
|
+
row: 6, column: 1, width: 640, height: 360,
|
|
869
|
+
legend: "bottom", dataLabels: { showValue: true, position: "outsideEnd" },
|
|
870
|
+
categoryAxis: { title: "Site" },
|
|
871
|
+
valueAxis: { title: "Controllers", minimum: 0, maximum: 30, numberFormat: "0.0" }
|
|
872
|
+
});
|
|
873
|
+
saveBlob(await book.toBlob(), "controllers.xlsx");
|
|
874
|
+
```
|
|
875
|
+
|
|
876
|
+
A snapshot chart captures its categories, series and options at `addChart`. Later caller mutations cannot change the export. The snapshot form above gets one hidden source worksheet with a workbook-unique name, separate from the report table. Unhide that worksheet in Excel to edit the chart's data; changing the visible report cells does not update this snapshot. Hidden source sheets count in the result's `sheets`; source rows do not count as report `rows` or row progress. Images and native charts can share the same worksheet, in Blob or streamed output.
|
|
877
|
+
|
|
878
|
+
Categories are strings; every series has the same number of finite numeric values. Series colors accept opaque six-digit RGB hex. Legends support `right` (the default), `bottom`, `left`, `top` or `false`. Column/bar/line charts support category/value axis titles, value bounds and number formats. Pie charts require one nonnegative series with at least one positive value and reject axes. Percent labels are available only for pie charts. Unsupported chart kinds, options and label positions fail explicitly; stacking, secondary axes, trendlines and arbitrary chart styles are outside this contract.
|
|
879
|
+
|
|
880
|
+
## Editable analysis workbooks
|
|
881
|
+
|
|
882
|
+
The advanced `Workbook` API writes authored numeric formulas, inline-list editing rules and native charts linked to visible worksheet data. Excel recalculates formulas when the workbook opens or values change; OfficeIMO writes the initial numeric caches supplied by the report producer.
|
|
883
|
+
|
|
884
|
+
```ts
|
|
885
|
+
import { Workbook, FormulaCell, saveBlob } from "@evotecit/officeimo/xlsx";
|
|
886
|
+
|
|
887
|
+
const statuses = ["Healthy", "Attention", "Offline"] as const;
|
|
888
|
+
const counts = { Healthy: 2, Attention: 0, Offline: 1 };
|
|
889
|
+
const book = new Workbook();
|
|
890
|
+
const services = book.addWorksheet("Services", {
|
|
891
|
+
columns: [{ header: "Status", key: "status" }],
|
|
892
|
+
table: { name: "Services" },
|
|
893
|
+
dataValidation: [{ type: "list", column: "status", items: statuses, allowBlank: false }]
|
|
894
|
+
});
|
|
895
|
+
await services.addRows([{ status: "Healthy" }, { status: "Offline" }, { status: "Healthy" }]);
|
|
896
|
+
await services.close();
|
|
897
|
+
const range = services.dataRange("status");
|
|
898
|
+
|
|
899
|
+
const overview = book.addWorksheet("Overview", {
|
|
900
|
+
columns: [{ header: "Status", key: "status" }, { header: "Services", key: "count", type: "number" }]
|
|
901
|
+
});
|
|
902
|
+
overview.addChart({
|
|
903
|
+
type: "columnClustered", title: "Service health",
|
|
904
|
+
data: { kind: "range", sheet: overview, rowCount: 3, categoryColumn: "status", series: [{ column: "count" }] },
|
|
905
|
+
row: 6, column: 1, width: 640, height: 340, legend: false
|
|
906
|
+
});
|
|
907
|
+
await overview.addRows(statuses.map(status => ({ status,
|
|
908
|
+
count: new FormulaCell(range ? `COUNTIF(${range},"${status}")` : "0", counts[status])
|
|
909
|
+
})));
|
|
910
|
+
saveBlob(await book.toBlob(), "service-analysis.xlsx");
|
|
911
|
+
```
|
|
912
|
+
|
|
913
|
+
Changing a service status in Excel updates the summary and its chart. If Excel uses manual calculation, recalculate to refresh them. The executable [service report job](../OfficeIMO.JavaScript.Examples/report-engine-job.mjs) computes initial caches during the same pass that writes the selected source rows. Its counts cover all exported records; filtering those records later in Excel does not change the `COUNTIF` summaries.
|
|
914
|
+
|
|
915
|
+
`FormulaCell(formula, cachedValue, style?)` accepts an explicit invariant XLSX storage expression, a finite numeric initial result or `null` for a blank cached result, and an optional workbook-local style index. An optional leading `=` is removed. Expressions contain 1–8,192 UTF-16 units and reject XML-invalid characters even under the text-strip policy. Direct external-workbook and DDE references are unsupported. Use English function names, commas and any required [future-function prefix](https://learn.microsoft.com/en-us/openspecs/office_standards/ms-xlsx/5d1b6d44-6fc1-4ecd-8fef-0b27406cc2bf), for example `_xlfn.AGGREGATE(9,0,A2:A10)`. The writer does not translate localized Excel entry syntax or add function prefixes. The author owns the expression's Excel semantics and cache accuracy; this is formula authoring, not a formula evaluator or sandbox. Ordinary strings remain literal values. Formula cells are supported in advanced worksheet rows, getters, custom-writer results and `footer.values`; portable table/CSV/PDF inputs and structured heading/footer matrices continue to accept resolved values. An explicit formula input cannot also pass through a custom column writer; return the formula from that writer instead.
|
|
916
|
+
|
|
917
|
+
`worksheet.dataRange(column)` returns a quoted, absolute, finite A1 reference after the worksheet closes, or `undefined` for empty data. Select a unique declared column key or one-based column number. Titles, heading matrices and footers are excluded. The reference describes the exported rows and does not expand when users add rows later.
|
|
918
|
+
|
|
919
|
+
A chart's `data: { kind: "range", sheet, rowCount, categoryColumn, series }` binds existing chart types to a visible worksheet in the same workbook. Register it while the source is idle, before its first selected row is serialized. Optional `firstRow` is a zero-based data-row offset; column numbers are one-based. Categories require strings and numeric series require finite numbers or numeric formula caches. The writer captures only the declared cache during its ordinary row pass. It emits references to actual source cells and creates no duplicate hidden source sheet. A series name uses the emitted matching leaf heading when available, or a literal supplied name. Bound charts omit hidden/filtered source points in Excel; snapshot charts retain their separate hidden-data behavior. Missing, truncated, foreign or late-bound sources fail explicitly.
|
|
920
|
+
|
|
921
|
+
Charts omit language metadata by default. Set `language: "pl-PL"` on a chart when its text needs an explicit language tag; valid tags are canonicalized without inferring the machine or report language.
|
|
922
|
+
|
|
923
|
+
`dataValidation` contains inline-list rules targeting a declared data column. Each rule supplies `type: "list"`, `column` and nonempty `items`. Items cannot contain commas, and the quoted list expression must fit Excel's 255 UTF-16-unit inline-source limit. `allowBlank` defaults to true; `showErrorMessage` defaults to true and `errorStyle` to `"stop"`. Optional `errorTitle` and `errorMessage` fit 32 and 255 UTF-16 units respectively. Rules follow the final exported data range, excluding headings and totals; empty sheets emit no validation elements. Excel validation is an editing aid, not a security boundary.
|
|
924
|
+
|
|
925
|
+
Workbook limits include `maxFormulaCharacters` (1,000,000 authored UTF-16 units), `maxDataValidations` (1,000 captured rules) and `maxValidationTextCharacters` (1,000,000 captured UTF-16 units). Bound caches share `maxChartPoints` and `maxChartTextCharacters`; formula expressions also consume the general text budget. These limits apply across the workbook, including editing rules declared on empty sources.
|
|
926
|
+
|
|
927
|
+
## Grouped analytical reports
|
|
928
|
+
|
|
929
|
+
`createGroupedReport` supplies one shared, single-use analytical stream to XLSX and PDF. It consumes rows already ordered into contiguous groups, with one through four levels from outermost to innermost. Every visible column has a unique stable `key`; translated or reordered headings never choose the grouping field or a metric. A closed group recurring under the same parent is rejected; the same child key under another parent is valid. The engine does not sort or retain all report rows.
|
|
930
|
+
|
|
931
|
+
```ts
|
|
932
|
+
import { createGroupedReport, writeGroupedXlsx, saveBlob } from "@evotecit/officeimo/xlsx";
|
|
933
|
+
|
|
934
|
+
const columns = [
|
|
935
|
+
{ header: "Site", key: "site" },
|
|
936
|
+
{ header: "Service", key: "service" },
|
|
937
|
+
{ header: "Latency", key: "latency", type: "number", format: "0.00" }
|
|
938
|
+
] as const;
|
|
939
|
+
const rows = [
|
|
940
|
+
{ site: "Berlin", service: "Directory", latency: 12 },
|
|
941
|
+
{ site: "Berlin", service: "DNS", latency: 18 },
|
|
942
|
+
{ site: "Warsaw", service: "Directory", latency: 6 }
|
|
943
|
+
];
|
|
944
|
+
const report = createGroupedReport(rows, {
|
|
945
|
+
columns, groupBy: "site", totals: { latency: "average" },
|
|
946
|
+
groupLabel: value => String(value ?? ""),
|
|
947
|
+
limits: { maxRows: 100000, maxCells: 300000 }
|
|
948
|
+
});
|
|
949
|
+
const file = await writeGroupedXlsx(report, {
|
|
950
|
+
labelColumn: { header: "Summary", width: 30 },
|
|
951
|
+
subtotalLabel: group => `${group.label}: ${group.rows} services`,
|
|
952
|
+
grandTotalLabel: summary => `All ${summary.rows} services`,
|
|
953
|
+
sheet: { name: "Service analysis", freezeHeader: true },
|
|
954
|
+
collapseGroups: true,
|
|
955
|
+
limits: { maxOutputBytes: 96000000 }
|
|
956
|
+
});
|
|
957
|
+
saveBlob(file, "grouped-services.xlsx");
|
|
958
|
+
```
|
|
959
|
+
|
|
960
|
+
The leading label column preserves every original typed column, including a numeric first column. `sum`, `count`, `average`, `min` and `max` operate on explicitly numeric columns and accept finite numbers or null values. `count` counts numeric cells; `group.rows` and `summary.rows` count all records. Empty sum/count results are zero; empty average/min/max results are blank. Every ancestor and the grand summary aggregate accepted numeric records directly, so unequal child sizes do not distort averages.
|
|
961
|
+
|
|
962
|
+
XLSX emits native outline controls and finite `SUBTOTAL` formulas with initial caches. Excel recalculates them after detail edits; manually collapsed rows remain included. Grouped sheets do not enable an Excel table or autofilter: filtering/selection belongs to the host capture before export. `includeGrandTotal: false` omits the final summary. Group labels, subtotal labels and grand labels are host-authored strings, so applications supply their own translations and terminology.
|
|
963
|
+
|
|
964
|
+
For PDF, create a fresh source and call `writeGroupedPdf` or `writeGroupedPdfTo` from the same `/pdf` entry. These convenience writers use the same composed-document owner as `pdfGroupedTable`. The required `labelColumn`, `subtotalLabel` and `grandTotalLabel` remain host-authored; ordinary PDF fonts, layout and display options apply. Continued pages repeat the full active ancestor path and leaf headings. `continuationLabel` supplies display text for each active group. Empty reports retain requested headings with or without a grand total.
|
|
965
|
+
|
|
966
|
+
Untagged output keeps the last detail row and its closing subtotals together when the bundle fits a fresh page; oversized bundles use ordinary row splitting under repeated context. The [tagged profile](#tagged-pdf-reports) nests group sections and gives nonblank labels a visible heading and navigation entry. A leaf subtotal shares its detail table and column headings; an ancestor subtotal uses a separate summary table under that ancestor's section, and the grand total follows the groups. Each summary row has a row-heading label associated with its values. Separate ancestor and grand-summary tables show the label and declared aggregate columns, including zero or blank results, with their own headings; detail-only fields do not create empty summary bands. The opening path is painted once by group headings and existing ancestor context, then repeated in full on later bands and pages. This presentation can use more space than the compact untagged layout. `groupHeadingLevel` sets the outer group's heading level, defaulting to 2; child groups increment it. Use 1 for a titleless report or 3 beneath an authored H2 section. An opened hierarchy extending beyond H6 fails explicitly.
|
|
967
|
+
|
|
968
|
+
`writeGroupedXlsxTo` and `writeGroupedPdfTo` await caller-owned destinations. Source and writer cancellation reach pending reads and writes; progress/result `rows` count data records. Generated group and summary rows still consume the format writer's row/cell/text budgets. Source `limits` cover only rows, cells and text; set `maxOutputBytes` on the selected writer. `maxGroups` defaults to 1,000 across all opened nodes, and `maxGroupKeyCharacters` to 1,000,000 retained UTF-16 units. The engine retains parent-scoped identifiers for recurrence detection, depth-bounded aggregate state and one boundary lookahead, rather than group bodies.
|
|
969
|
+
|
|
970
|
+
Group identity is locale independent: strings compare exactly, numbers and booleans keep their types, dates compare UTC milliseconds, and null/undefined share one empty group. Default date labels use ISO UTC text; use a level descriptor's `label` for localized display, or the single-level `groupLabel` shorthand. Use the factory and writer from the same package entry or standalone bundle. A source is consumed once; create another source, with a new iterable when necessary, for a second format. CSV remains a flat typed-record export.
|
|
971
|
+
|
|
972
|
+
### Compose a hierarchical analysis
|
|
973
|
+
|
|
974
|
+
`groupBy: ["region", "site"]` selects projected values by stable column key. For a grouping field that should not appear in the detail columns, supply `{ key, value, label? }`. Its synchronous getter receives the original record and `{ rowIndex, level, key }`; an existing visible column reuses its captured projection and cannot also declare a grouping getter. Each label callback receives the typed key. Levels require unique keys; `groupLabel` applies only to a single level.
|
|
975
|
+
|
|
976
|
+
```ts
|
|
977
|
+
import { Workbook, createGroupedReport, addGroupedXlsx, saveBlob } from "@evotecit/officeimo";
|
|
978
|
+
|
|
979
|
+
const selected = [
|
|
980
|
+
{ portfolio: "Core", environment: "Production", service: "Directory", latency: 12 },
|
|
981
|
+
{ portfolio: "Core", environment: "Production", service: "DNS", latency: 18 },
|
|
982
|
+
{ portfolio: "Core", environment: "Staging", service: "Directory", latency: 6 }
|
|
983
|
+
];
|
|
984
|
+
const source = createGroupedReport(selected, {
|
|
985
|
+
columns: [
|
|
986
|
+
{ header: "Service", key: "service" },
|
|
987
|
+
{ header: "Latency", key: "latency", type: "number", format: "0.00" }
|
|
988
|
+
],
|
|
989
|
+
groupBy: [
|
|
990
|
+
{ key: "portfolio", value: row => row.portfolio },
|
|
991
|
+
{ key: "environment", value: row => row.environment }
|
|
992
|
+
],
|
|
993
|
+
totals: { latency: "average" }
|
|
994
|
+
});
|
|
995
|
+
const book = new Workbook();
|
|
996
|
+
await book.addWorksheet("Context", { columns: [{ header: "Scope" }] })
|
|
997
|
+
.addRows([["Selected services; grouping fields are metadata."]]);
|
|
998
|
+
const analysis = await addGroupedXlsx(book, source, {
|
|
999
|
+
labelColumn: { header: "Group", width: 30 },
|
|
1000
|
+
subtotalLabel: group => `${group.label}: ${group.rows} services`,
|
|
1001
|
+
grandTotalLabel: summary => `All ${summary.rows} selected services`,
|
|
1002
|
+
sheet: { name: "Analysis", freezeHeader: true },
|
|
1003
|
+
conditionalFormats: [{ type: "cellIs", range: { column: "latency" },
|
|
1004
|
+
operator: "greaterThan", value: 15, style: { font: { bold: true, color: "991B1B" } } }]
|
|
1005
|
+
});
|
|
1006
|
+
const overview = book.addWorksheet("Overview", {
|
|
1007
|
+
columns: [{ header: "Portfolio" }, { header: "Services", type: "number" }]
|
|
1008
|
+
});
|
|
1009
|
+
await overview.addRows(analysis.groups.filter(group => group.level === 0)
|
|
1010
|
+
.map(group => [group.label, group.rows]));
|
|
1011
|
+
saveBlob(await book.toBlob(), "selected-services.xlsx");
|
|
1012
|
+
```
|
|
1013
|
+
|
|
1014
|
+
`addGroupedXlsx` closes its new analysis worksheet and leaves the existing workbook open for further sheets and finalization. It shares that workbook's styles, destination, cancellation and cumulative limits. Its result contains `worksheet`, accepted `rows`, output `columns`, `grandSummary`, physical `detailRanges`, per-group identity/path/rows/totals and `startRow`, `firstDetailRow`, `lastDetailRow`, `summaryRow`, plus optional `grandTotalRow`. Coordinates are one-based physical worksheet positions. `Worksheet.rowCount` includes generated analysis rows; workbook result/progress row counts exclude those generated rows and still include ordinary sibling-sheet data. On a grouped worksheet, `dataRange()` returns its single contiguous detail run or `undefined` for no details. Multiple detail runs require the explicit `detailRanges`; a single rectangular range would also include generated totals and is rejected.
|
|
1015
|
+
|
|
1016
|
+
Top-level grouped `conditionalFormats` and `dataValidation` apply only to the returned detail runs. Select a stable data-column key or one-based visible data-column number; the added label column does not change those selectors. A1 rule ranges and generated rows are rejected. Inline validation retains the ordinary Excel limits. Disjoint editing references are bounded to 32,767 UTF-16 units; split a worksheet if its group count would exceed that ceiling. Native tables and autofilters remain unsupported for interleaved detail and summary rows.
|
|
1017
|
+
|
|
1018
|
+
For a PDF document, create a fresh source and insert `pdfGroupedTable(source, labelsAndTableOptions)` alongside sections, paragraphs, charts, ordinary tables and recommendations. The block inherits fonts, page geometry, cancellation and resource policy from `writePdfDocument`/`writePdfDocumentTo`. Block options contain table presentation and labels; document options belong on the document writer. A grand total moved or split onto a fresh page repeats the metric headings unless `includeHeader: false` was requested. Ownership of a source begins when its block is reached, and a completed, failed or cancelled block releases its iterator and listeners. An unreached block does not consume its source.
|
|
1019
|
+
|
|
1020
|
+
Group events expose zero-based `level` and a captured `path` containing all active `{ groupIndex, key, label, level }` identities. `source.groupBy` is a readonly array of stable level keys. A composed report can use a supplied opening overview, or create a computed overview after consuming the detail. It does not silently replay a source or retain its complete body to compute an earlier summary. Totals describe the actual exported rows, including selected/filtered captures; a grid's full-query summary is a different scope.
|
|
1021
|
+
|
|
1022
|
+
The [complete analytical report example](../OfficeIMO.JavaScript.Examples/analytical-report-job.mjs) combines hidden grouping fields, detail-only editing rules, an editable overview chart and multi-section PDF output. Its worker input is ordinary flat projected rows: visible values followed by explicitly selected grouping scalars. Those metadata fields consume the same worker cell/text budgets; callbacks are reconstructed in the worker. It has explicit English and Polish example resources, while the engine's keys, grouping and numeric semantics remain language independent.
|
|
1023
|
+
|
|
1024
|
+
The [HtmlForgeX operational inventory example](../OfficeIMO.JavaScript.Examples/OperationalInventoryExample.cs) generates a typed table with selection, filtering and column reordering. Its host captures the current view and sends portable values and explicit column metadata to a worker using the public grouped XLSX/PDF writers. Stable service keys identify repeated PDF columns and row headings; the table's presentation remains under the host's control.
|
|
1025
|
+
|
|
1026
|
+
## Live Excel conditional formatting
|
|
1027
|
+
|
|
1028
|
+
`conditionalFormats` writes native Excel rules that recalculate when users edit workbook values. Use these alongside resolved row/cell highlights when the report needs both an exported appearance and live spreadsheet behavior:
|
|
1029
|
+
|
|
1030
|
+
```ts
|
|
1031
|
+
import { Workbook } from "@evotecit/officeimo/xlsx";
|
|
1032
|
+
|
|
1033
|
+
const book = new Workbook({ limits: { maxConditionalFormats: 100, maxDifferentialStyles: 50 } });
|
|
1034
|
+
const sheet = book.addWorksheet("Latency", {
|
|
1035
|
+
columns: [
|
|
1036
|
+
{ header: "Name", key: "name", width: 24 },
|
|
1037
|
+
{ header: "Latency", key: "latency", type: "number", format: "0.000", width: 18 }
|
|
1038
|
+
],
|
|
1039
|
+
table: { name: "LatencyReport" },
|
|
1040
|
+
conditionalFormats: [
|
|
1041
|
+
{ type: "cellIs", range: { column: "latency" }, operator: "greaterThan", value: 100,
|
|
1042
|
+
style: { fill: { color: "FFC7CE" }, font: { color: "9C0006" } }, stopIfTrue: true },
|
|
1043
|
+
{ type: "expression", range: { column: "name", through: "latency" }, formula: "$B2>100",
|
|
1044
|
+
style: { font: { bold: true } } },
|
|
1045
|
+
{ type: "dataBar", range: { column: "latency" }, color: "638EC6" }
|
|
1046
|
+
]
|
|
1047
|
+
});
|
|
1048
|
+
await sheet.addRows([{ name: "Łódź", latency: 125.75 }, { name: "Warsaw", latency: 25 }]);
|
|
1049
|
+
const blob = await book.toBlob();
|
|
1050
|
+
```
|
|
1051
|
+
|
|
1052
|
+
A column target uses an unambiguous declared key or a one-based column number. Optional `through` extends it across adjacent columns. The writer resolves the final data range after all appends, excluding report titles, grouped/leaf headings and footer totals. An empty data export emits no column-targeted rule. An explicit uppercase A1 cell or rectangle, such as `"B2:B20"`, can include headings or totals but must stay within the declared columns and exported rows; row bounds are checked when the worksheet closes. Overlapping rules are supported.
|
|
1053
|
+
|
|
1054
|
+
| Rule type | Contract |
|
|
1055
|
+
| --- | --- |
|
|
1056
|
+
| `cellIs` | `equal`, `notEqual`, `greaterThan`, `greaterThanOrEqual`, `lessThan` or `lessThanOrEqual` with one finite numeric `value`; `equal` and `notEqual` also accept literal text. `between` or `notBetween` with an ordered pair of numeric `values`. Dates can be compared using Excel serial numbers or an expression. |
|
|
1057
|
+
| `expression` | An Excel formula and a differential `style`. Relative references are anchored to the top-left cell of the target range; use the first data row appropriate to your title/heading layout. |
|
|
1058
|
+
| `colorScale` | Two or three `stops`, each with a hex `color` and `threshold`. |
|
|
1059
|
+
| `dataBar` | A hex `color`, optional `minimum`/`maximum` thresholds and `showValue`, default true. Writes standard gradient data bars. |
|
|
1060
|
+
|
|
1061
|
+
Thresholds use `{ type: "min" }` at the start, `{ type: "max" }` at the end, `{ type: "number", value: 100 }`, percent/percentile values from 0 through 100, or `{ type: "formula", value: "MAX($B$2:$B$20)" }`. Color scales require two or three stops; a three-color scale can use a 50th-percentile middle stop. Numeric thresholds of the same type must be ordered. Data bars default to the range minimum and maximum. Icon sets and Office extension features such as solid bars, negative-bar colors and axes are outside this writer contract.
|
|
1062
|
+
|
|
1063
|
+
Array order sets worksheet-wide rule priority, starting at one. `stopIfTrue` applies to comparison and expression rules. A differential style changes only supplied font flags/color, solid fill, individual border edges or a number-format string. Explicit `false` clears a font flag. Omitting the number format preserves the cell's existing numeric/date formatting; font family/size, wrapping, alignment and numeric style-component indexes are unsupported in differential styles and fail explicitly.
|
|
1064
|
+
|
|
1065
|
+
Rules are captured at worksheet creation and retain metadata rather than source rows or per-cell style assignments. Identical differential styles share one workbook definition. `maxConditionalFormats` and `maxDifferentialStyles` each default to 1,000 across the workbook, independently of `maxStyles`; zero disables the corresponding feature. Even a column rule on an empty worksheet counts toward the rule limit. Formula text uses invariant Excel syntax, accepts an optional leading `=`, and is limited to 8,192 characters. The writer stores formulas without evaluating them; XML-invalid formula characters are rejected under either text policy so cleanup cannot change their meaning. CSV does not carry conditional rules.
|
|
1066
|
+
|
|
1067
|
+
## CSV
|
|
1068
|
+
|
|
1069
|
+
```ts
|
|
1070
|
+
import { writeCsv, writeCsvTo, saveBlob } from "@evotecit/officeimo/csv";
|
|
1071
|
+
|
|
1072
|
+
const columns = [{ header: "Name" }, { header: "Healthy" }];
|
|
1073
|
+
const rows = [["Łódź", true], ["=literal", false]] as const;
|
|
1074
|
+
saveBlob(await writeCsv(rows, { columns, bom: true }), "status.csv");
|
|
1075
|
+
|
|
1076
|
+
// A caller-owned destination can avoid retaining the final CSV Blob.
|
|
1077
|
+
await writeCsvTo(rows, { write: bytes => uploadChunk(bytes) }, { columns });
|
|
1078
|
+
```
|
|
1079
|
+
|
|
1080
|
+
`uploadChunk` above stands for an application's asynchronous byte destination; its promise supplies backpressure. The library performs no network access itself. Both CSV entry points use RFC 4180 quoting, comma/semicolon/tab delimiters, CRLF by default, optional UTF-8 BOM and a final line ending. Alternative endings are LF and CR. Booleans default to `True`/`False`; `booleanText: { true: "Tak", false: "Nie" }` supplies explicit display labels. Valid dates are UTC ISO 8601 with milliseconds. Numbers use JavaScript's invariant string representation.
|
|
1081
|
+
|
|
1082
|
+
Formula protection defaults to true and follows `OfficeIMO.CSV`: after leading ASCII spaces, a string beginning with `=`, `+`, `-`, `@`, tab, CR or LF gains an apostrophe. Typed negative numbers remain numeric. Set `formulaInjectionProtection: false` for trusted non-spreadsheet consumers. Widths and XLSX style/type options do not change CSV formatting.
|
|
1083
|
+
|
|
1084
|
+
CSV carries values rather than colors or fonts. Use a column's synchronous `valueFormatter` to export status labels, chosen date formats or other scalar representations. Formatting runs before formula protection and quoting, so return plain values rather than escaped CSV:
|
|
1085
|
+
|
|
1086
|
+
```ts
|
|
1087
|
+
const blob = await writeCsv([{ name: "Łódź", healthy: false }], {
|
|
1088
|
+
columns: [
|
|
1089
|
+
{ header: "Name", key: "name" },
|
|
1090
|
+
{ header: "Status", key: "healthy", valueFormatter: value => value ? "Healthy" : "Needs attention" }
|
|
1091
|
+
],
|
|
1092
|
+
bom: true, quote: "strings", nullValue: "missing"
|
|
1093
|
+
});
|
|
1094
|
+
```
|
|
1095
|
+
|
|
1096
|
+
`quote` defaults to `"minimal"`; `"all"` quotes every field and `"strings"` always quotes string values. Required delimiter, quote and newline escaping applies in every mode. `nullValue` replaces null/undefined values and receives the same protection and quoting as other strings. Formatters run on data only; their context contains zero-based data `rowIndex` and `columnIndex`, column definition and original projected `values`. Both Blob and caller-owned sink APIs share these options. CSV retains long text that exceeds Excel's per-cell text limit.
|
|
1097
|
+
|
|
1098
|
+
`headerRows` and `footer: { rows }` accept the same rectangular matrices as XLSX. CSV preserves their physical rows and requires `spanMode` whenever an emitted matrix spans cells: `"repeat"` writes the anchor value in every covered field; `"anchors"` writes it once and leaves covered fields empty. `includeHeader: false` suppresses the heading matrix. Display selection, quoting and formula protection still apply; column value formatters run only on data rows. Metadata rows do not increase data-row progress or completion counts.
|
|
1099
|
+
|
|
1100
|
+
The [shared vectors](../OfficeIMO.TestAssets/CSV/browser-exports.json) qualify byte-identical output with C#. The C# date lane uses `UseUtc = true` and `DateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss.fff'Z'"`. JavaScript and .NET use their own floating-point formatting conventions; equality is qualified for the shared numeric vectors, not every possible double.
|
|
1101
|
+
|
|
1102
|
+
## Core: sinks, cancellation and download
|
|
1103
|
+
|
|
1104
|
+
```ts
|
|
1105
|
+
import { BlobByteSink, ChunkedTextSink, detectFeatures } from "@evotecit/officeimo/core";
|
|
1106
|
+
|
|
1107
|
+
const bytes = new BlobByteSink();
|
|
1108
|
+
const text = new ChunkedTextSink(bytes);
|
|
1109
|
+
await text.write("Zażółć gęślą jaźń 🧪");
|
|
1110
|
+
await text.close();
|
|
1111
|
+
const blob = bytes.toBlob("text/plain;charset=utf-8");
|
|
1112
|
+
console.log(detectFeatures().deflateRaw, blob.size);
|
|
1113
|
+
```
|
|
1114
|
+
|
|
1115
|
+
A `ByteSink` implements `write(Uint8Array): void | Promise<void>`. It must accept the bytes before resolving. `BlobByteSink` copies input buffers, so callers can reuse them. `ChunkedTextSink` emits bounded UTF-8 batches and preserves surrogate pairs at append/chunk boundaries. Text buffering and grid projection share a cooperative yield after roughly 32 ms of work, using the browser task scheduler when available. This amortizes task scheduling without blocking for a complete large export. A caller can still supply one large source string or a slow synchronous callback; the budget does not interrupt that synchronous work. `writeBytes` connects a byte iterable to a sink.
|
|
1116
|
+
|
|
1117
|
+
Choose CSV for a values-only exchange and XLSX when readers need typed dates/numbers, report layout, highlighting, filtering or formulas. Blob helpers suit downloads whose completed file fits in memory. For large exports, pass a destination to `writeCsvTo` or `writeXlsxTo`, consume a paged async source and await each write; a host-owned worker can keep generation away from the page. The writers yield between batches so page events and cancellation can run. Source getters, formatters and destination callbacks still run in the caller's context and should finish promptly.
|
|
1118
|
+
|
|
1119
|
+
Pass an `AbortSignal` and synchronous `onProgress` to the writers. CSV/XLSX progress counts exclude headings and footers. XLSX `rows` is the workbook-wide data total; row events additionally identify `sheetName` and `sheetRows`. DataTables adds its captured `totalRows`. Completion reports the accepted output bytes. Throwing from a callback fails the export. Cancellation returns producer iterators and rejects pending input or sink operations. On failure, writers invoke producer cleanup and observe its result; a pending or rejected cleanup does not delay or replace the export error. A cancelled `finish()` or `toBlob()` releases owned output and rejects its returned promise with the original signal reason, including cancellation between calls. Give I/O producers and destinations the same signal so they can release their own resources.
|
|
1120
|
+
|
|
1121
|
+
`OfficeIMOError.code` identifies package/state/platform failures; `NotSupportedError` adds a `feature`. Input type and range errors use native `TypeError` and `RangeError`; cancellation preserves the signal's original reason. `saveBlob` requires a browser document. Node and workers should deliver their Blob through their own host mechanisms.
|
|
1122
|
+
|
|
1123
|
+
## ZIP
|
|
1124
|
+
|
|
1125
|
+
```ts
|
|
1126
|
+
import { ZipWriter } from "@evotecit/officeimo/zip";
|
|
1127
|
+
|
|
1128
|
+
const zip = new ZipWriter();
|
|
1129
|
+
await zip.add("data/status.txt", new TextEncoder().encode("Łódź 🧪"));
|
|
1130
|
+
const blob = await zip.toBlob();
|
|
1131
|
+
```
|
|
1132
|
+
|
|
1133
|
+
Pass a `ByteSink` as the constructor's first argument for direct streaming, then call `finish`. Each entry accepts bytes, a byte iterable or a callback that writes chunks to the supplied entry sink. Writes are sequential and use ZIP data descriptors. Only central-directory metadata is retained by the streaming writer; the caller owns its destination and partial-byte disposal on failure. `Crc32` exposes incremental CRC for future readers and independent integrations.
|
|
1134
|
+
|
|
1135
|
+
`compression: "auto"` uses platform `CompressionStream("deflate-raw")`; missing raw-deflate support falls back to stored entries. `"store"` forces that fallback. No external compressor is loaded. Paths must be relative and reject traversal, backslashes, empty segments and duplicates. ZIP64 is explicitly unsupported: entry/archive sizes must stay below 4 GiB and an archive can contain at most 65,534 entries. Reaching a ZIP64 boundary throws `code: "ZIP64_REQUIRED"`.
|
|
1136
|
+
|
|
1137
|
+
`openEntry(name)` returns an appendable entry sink with `write` and `close`; close it before starting the next entry or finishing the archive. `maxOutputBytes` can bound actual archive bytes. Blob-returning APIs retain output proportional to file size; stored output can be substantially larger. Streaming input does not imply constant memory for a final Blob. Readers are outside the current API.
|
|
1138
|
+
|
|
1139
|
+
## XML
|
|
1140
|
+
|
|
1141
|
+
```ts
|
|
1142
|
+
import { XmlWriter } from "@evotecit/officeimo/xml";
|
|
1143
|
+
import { BlobByteSink } from "@evotecit/officeimo/core";
|
|
1144
|
+
|
|
1145
|
+
const sink = new BlobByteSink();
|
|
1146
|
+
const xml = new XmlWriter(sink, "reject");
|
|
1147
|
+
await xml.startElement("report", { title: "A < B" });
|
|
1148
|
+
await xml.text("Łódź & Warsaw");
|
|
1149
|
+
await xml.endElement();
|
|
1150
|
+
await xml.close();
|
|
1151
|
+
```
|
|
1152
|
+
|
|
1153
|
+
The writer validates schema-owned ASCII QNames, escapes every attribute/text value, preserves XML whitespace through character references and checks document completeness. Always pass user content as values or `text`, never as names. There is no raw-XML method on `XmlWriter`. `escapeXml` and `cleanXml` expose the same strip/reject policy for format implementations.
|
|
1154
|
+
|
|
1155
|
+
## OPC
|
|
1156
|
+
|
|
1157
|
+
```ts
|
|
1158
|
+
import { OpcPackage, relationshipTypes } from "@evotecit/officeimo/opc";
|
|
1159
|
+
|
|
1160
|
+
const packageFile = new OpcPackage();
|
|
1161
|
+
packageFile.addPart({ uri: "/customXml/item1.xml", contentType: "application/xml", data: '<data xmlns="urn:report">value</data>' });
|
|
1162
|
+
packageFile.addRelationship("/", { id: "data", type: relationshipTypes.customXml, target: "/customXml/item1.xml" });
|
|
1163
|
+
packageFile.setProperties({ creator: "Report" }, { application: "OfficeIMO", company: "Evotec" });
|
|
1164
|
+
const blob = await packageFile.toBlob();
|
|
1165
|
+
```
|
|
1166
|
+
|
|
1167
|
+
OPC owns `[Content_Types].xml`, relationship parts, core/app properties and canonical part URIs. Internal relationship targets are absolute part URIs; the package serializes their relative spelling and checks that source/target parts exist. Case-insensitive part collisions, reserved metadata paths, invalid content types and duplicate relationship IDs throw. Unicode part names use UTF-8 percent encoding; `partUri`, `relationshipPartUri` and `relativePartTarget` expose URI operations. `ContentTypes` can also be used independently.
|
|
1168
|
+
|
|
1169
|
+
`OpcPackage({ sink })` supports `openPart(uri, contentType)` for direct incremental output. Close each part before opening the next; register relationships and deferred parts as usual, then call `finish()`. It returns the archive byte count without closing the sink. A package with a caller-owned sink uses `finish()` rather than `toBlob()`.
|
|
1170
|
+
|
|
1171
|
+
Part sources are strings, Blobs, bytes, byte iterables or entry-sink callbacks. Some local-file WebKit worker contexts block every native Blob-reading API. A Blob part that cannot be read throws `OfficeIMOError` with `code: "PLATFORM_UNAVAILABLE"` and the native error as `cause`; no package is returned. For those workers, read input Blobs in the host and transfer byte arrays, or supply text/byte producers. Returning an output Blob from the worker remains supported because the library does not read it there. Raw XML part sources are trusted schema documents supplied by the format module or extension; use `XmlWriter` for user data. OPC does not parse or repair supplied XML.
|
|
1172
|
+
|
|
1173
|
+
## Extensions and current boundaries
|
|
1174
|
+
|
|
1175
|
+
```ts
|
|
1176
|
+
import { Workbook } from "@evotecit/officeimo/xlsx";
|
|
1177
|
+
import { relationshipTypes } from "@evotecit/officeimo/opc";
|
|
1178
|
+
|
|
1179
|
+
const workbook = new Workbook({ cellValueWriters: { milliseconds: value => Number(value) / 1000 } });
|
|
1180
|
+
await workbook.addWorksheet("Timings", { columns: [{ header: "Seconds", type: "milliseconds", format: "0.000" }] }).addRows([["1250"]]);
|
|
1181
|
+
workbook.addPart({
|
|
1182
|
+
uri: "/customXml/item1.xml", contentType: "application/xml", data: '<data xmlns="urn:report">metadata</data>',
|
|
1183
|
+
relationship: { id: "custom", type: relationshipTypes.customXml }
|
|
1184
|
+
});
|
|
1185
|
+
const blob = await workbook.toBlob();
|
|
1186
|
+
```
|
|
1187
|
+
|
|
1188
|
+
`Workbook.addWorksheet` and `addChart` capture their configuration during registration. Nested registration from an option, column or style getter fails with `OfficeIMOError` code `INVALID_STATE`; prepare dependent inputs before registering them. A rejected nested call does not prevent later registration.
|
|
1189
|
+
|
|
1190
|
+
Column writers synchronously convert a domain column type to a supported scalar or styled `Cell`. They receive the column, zero-based `rowIndex`/`columnIndex`, one-based `worksheetRow` and `sheetName`. They cannot inject raw cell XML. Extra parts can carry custom XML, a valid theme or other schema-owned content. An optional internal relationship defaults to `/xl/workbook.xml`; supply `source` for another existing part. Part/relationship definitions are copied when registered; producer iterables remain caller-owned until consumed.
|
|
1191
|
+
|
|
1192
|
+
`dataValidation` supports the [inline-list editing profile](#editable-analysis-workbooks). There is no DOCX, PPTX, reader or formula evaluation engine in this package's current writer contract. Grid-specific selection and rendering belong to optional integrations such as the DataTables entry. Row/cell callbacks resolve highlighting during export; `conditionalFormats` separately writes the supported native rules for Excel to evaluate. The [roadmap](../Docs/ROADMAP.md#officeimo-javascript) records the remaining work.
|
|
1193
|
+
|
|
1194
|
+
## Portable classic scripts and the .NET asset package
|
|
1195
|
+
|
|
1196
|
+
The archive exports `@evotecit/officeimo/classic.js`, `/xlsx.js`, `/csv.js`, `/pdf.js` and optional `/execution.js` for copying into a portable report. Load the chosen asset with a plain script tag:
|
|
1197
|
+
|
|
1198
|
+
```html
|
|
1199
|
+
<script src="officeimo.js"></script>
|
|
1200
|
+
<script>
|
|
1201
|
+
const workbook = new OfficeIMO.xlsx.Workbook();
|
|
1202
|
+
const sink = new OfficeIMO.core.BlobByteSink();
|
|
1203
|
+
</script>
|
|
1204
|
+
```
|
|
1205
|
+
|
|
1206
|
+
The combined bundle exposes all seven namespaces on global `OfficeIMO` plus the established root helpers. The XLSX bundle exposes `core`, `zip`, `xml`, `opc`, `xlsx`; CSV exposes `core`, `csv`; PDF exposes `core`, `pdf`. Load `officeimo-execution.js` beside the chosen writer to add `executeWorkerExport` and `handleWorkerExports` to `OfficeIMO`. The standalone bundles compose in either order. Classic scripts work from `file://` and in host-owned workers without a module loader. ES modules use normal import paths on HTTP(S) and in Node; browser local-file module policy can block `file://` imports.
|
|
1207
|
+
|
|
1208
|
+
[OfficeIMO.JavaScript.Assets](../OfficeIMO.JavaScript.Assets/README.md) embeds the same committed TypeScript-built bundles in .NET. Its `JavaScriptAsset` API returns exact content and content-hashed filenames; consuming .NET applications require no Node tooling. Standalone `.mjs` assemblies preserve the asset package's module API. The npm subpaths remain genuine separate `tsc` modules with generated declarations.
|
|
1209
|
+
|
|
1210
|
+
## Build and validation
|
|
1211
|
+
|
|
1212
|
+
```sh
|
|
1213
|
+
npm run build
|
|
1214
|
+
npm test
|
|
1215
|
+
npm run test:consumer
|
|
1216
|
+
npm run test:pack -- /path/to/evidence/npm
|
|
1217
|
+
npm run test:browser -- /path/to/evidence/browser
|
|
1218
|
+
npm run sizes -- /path/to/evidence/sizes.json
|
|
1219
|
+
```
|
|
1220
|
+
|
|
1221
|
+
`npm test` compiles strictly, checks committed bundles and runs Node's built-in runner. `npm run check` fails when a bundle differs from the compiled graph. No bundler or minifier is used. On Windows, `npm --script-shell pwsh` can select PowerShell 7 when the machine's default npm shell cannot resolve its tools.
|
|
1222
|
+
|
|
1223
|
+
The browser command uses the repository's existing isolated HtmlTinkerX/Playwright runner and pinned .NET SDK. It checks Chromium, Firefox and WebKit, classic `file://` scripts, ESM imports, workers, downloads and the shared corpus. [C# conformance tests](../OfficeIMO.JavaScript.Assets.Tests/JavaScriptConformanceTests.cs) independently open produced workbooks with OfficeIMO.Excel/OfficeIMO.Reader.Excel and validate them with the Open XML SDK. The [architecture guide](../Docs/officeimo.javascript-architecture.md) describes API stability, format ownership and adding a module.
|