Shared concepts

Production decisions.

Choices that apply across DOCX, XLSX, and PPTX.

Choose where layout and paint run.

Parsing always runs in a Worker. Keep the default mode: 'main' for ordinary previews. Choose mode: 'worker' when document layout and Canvas paint compete with your application's UI.

mainworker
Layout and paintMain threadWeb Worker
Best fitMost previews and custom renderer objectsLarge or complex files
Browser requirementCanvasWorker and OffscreenCanvas

Let one Viewer own one document, unless views need to share it.

The usual path is to construct a Viewer, call load(source), and destroy the Viewer when its host unmounts. The Viewer owns the loaded document.

Load the document model yourself only when several views must share one parse. Destroy every borrowed view before destroying the shared model.

FormatShared modelBorrowing factory
DOCXDocxDocumentfromDocument()
PPTXPptxPresentationfromPresentation()
XLSXXlsxWorkbookfromWorkbook()
import { DocxDocument, DocxScrollViewer } from '@silurus/ooxml/docx';

const document = await DocxDocument.load(source, { mode: 'worker' });
const first = DocxScrollViewer.fromDocument(firstContainer, document);
const second = DocxScrollViewer.fromDocument(secondContainer, document);

// Destroy every view before the shared document.
first.destroy();
second.destroy();
document.destroy();

Add only the rendering modules a product needs.

Equations, ChartEx, 3-D charts, Region Maps, and TIFF images use separate package entries. Import a module once and pass it to the Viewer or document engine. The same option works across DOCX, XLSX, and PPTX, including main and worker rendering modes.

Omit a module when the product does not need that content. Its main-mode implementation stays outside the ordinary format import graph, while built-in capabilities such as classic 2-D charts remain available. The separately loaded render-worker asset is self-contained so it can render enabled first-party modules without another download.

Try Yours and the VS Code extension enable every first-party optional module. Applications built with the library choose their own set using the imports below.

import { XlsxViewer } from '@silurus/ooxml/xlsx';
import { math } from '@silurus/ooxml/math';
import { chartEx } from '@silurus/ooxml/chart-ex';
import { threeD } from '@silurus/ooxml/three-d';
import { regionMap } from '@silurus/ooxml/region-map';
import { tiff } from '@silurus/ooxml/tiff';

const viewer = new XlsxViewer(container, {
  math,
  chartEx,
  threeD,
  regionMap,
  tiff,
});
CapabilityImportViewer option
Equation renderer @silurus/ooxml/math math
Microsoft ChartEx renderer @silurus/ooxml/chart-ex chartEx
3-D chart renderer @silurus/ooxml/three-d threeD
Offline Region Map renderer @silurus/ooxml/region-map regionMap
TIFF image codec @silurus/ooxml/tiff tiff

A small TIFF reuse

The TIFF module exists to display images embedded in Office files; it is not a general-purpose TIFF library. As a small by-product, applications can reuse it for a simple preview of a standalone TIFF file when that file is in the currently supported class. Unsupported or malformed TIFF variants reject with a diagnostic error.

import { tiff } from '@silurus/ooxml/tiff';

const bytes = new Uint8Array(await file.arrayBuffer());
const bitmap = await tiff.render(bytes);

if (bitmap) {
  const canvas = document.getElementById('preview') as HTMLCanvasElement;
  canvas.width = bitmap.width;
  canvas.height = bitmap.height;
  canvas.getContext('2d')?.drawImage(bitmap, 0, 0);
  bitmap.close();
}