The envelope definition (detect / decode / encode).
An envelope is format-independent — it wraps whatever bytes a format handler produced — so registering one enables password support for every registered format at once. See IWorkbookIO.EncryptionType.
Registers a new read format type or replaces an existing one.
The format type definition containing decoder logic.
Use this to add support for new workbook encoding formats (not source types).
If a format with the same key already exists, it will be replaced.
This allows you to:
The registered format will work with all source types automatically.
// Register a custom XML-based format
workbookIO.registerReadFormat({
key: 'custom-xml',
description: 'Custom XML Workbook Format',
mimeType: 'application/x-custom-workbook+xml',
exts: ['.cwb', '.cxml'],
tags: ['xml', 'custom'],
handler: async (buffer, options) => {
// Decode buffer into IWorkbook
const xmlString = new TextDecoder().decode(buffer);
return parseCustomXML(xmlString);
}
});
// Now any source type can use this format
await workbookIO.read({ source: 'data.cwb' }); // Auto-detected
await workbookIO.read({ source: fileObject, format: 'custom-xml' });
Registers a new write format type or replaces an existing one.
The format type definition containing encoder logic.
Use this to add support for new workbook encoding formats (not source types).
If a format with the same key already exists, it will be replaced.
This allows you to:
The registered format can then be written to any source type (File, ArrayBuffer, etc.).
// Register a custom JSON-based format
workbookIO.registerWriteFormat({
key: 'custom-json',
description: 'Custom JSON Workbook Format',
mimeType: 'application/json',
ext: '.cjson',
tags: ['json', 'custom'],
handler: async (workbook, options) => {
// Encode workbook into ArrayBuffer
const jsonString = JSON.stringify(customSerialize(workbook));
return new TextEncoder().encode(jsonString).buffer;
}
});
// Use with any write method
await workbookIO.write(workbook, { fileName: 'report.cjson' });
const buffer = await workbookIO.writeArrayBuffer(workbook, { format: 'custom-json' });
Registers an encryption envelope, or replaces an existing one with the same
key.