Skip to content
Document Authoring DA  API Docs v2.0.0
npmGitHub

DocAuthSpreadsheetNEW

DocAuthSpreadsheet:

An open spreadsheet.

The spreadsheet’s counterpart of DocAuthDocument: what the system hands back when it opens a file, and what saves and exports it. It does not expose the cells.

// Open a file, show it, and save what the user has done to it
const spreadsheet = await system.importSpreadsheet(file);
const editor = await system.createSpreadsheetEditor(target, { spreadsheet });
// ... user edits the grid ...
const saved = await editor.currentSpreadsheet().saveSpreadsheet();

saveSpreadsheet(): Promise<Blob>

Returns the spreadsheet in the Document Authoring spreadsheet format, as a Blob.

This works at every spreadsheet size, including one with millions of rows, and is the one to prefer. A large spreadsheet is written by streaming, so it never exists in memory as a single value.

Promise<Blob>

// Persist to a server
const saved = await spreadsheet.saveSpreadsheet();
await fetch('/api/spreadsheets/123', { method: 'PUT', body: saved });
// Save and reopen — the lossless round trip
const saved = await spreadsheet.saveSpreadsheet();
const reopened = await system.loadSpreadsheet(saved);

saveSpreadsheetJSONString(): Promise<string>

The same bytes as a JSON string, or an empty string if the spreadsheet is too large to be one.

A very large spreadsheet exceeds the JavaScript engine’s maximum string length; this method then returns "". Treat an empty result as “use DocAuthSpreadsheet.saveSpreadsheet”.

Promise<string>

// Embed the spreadsheet in a JSON request, falling back to a binary upload when it is too large to be a
// string. Always handle the empty result.
const json = await spreadsheet.saveSpreadsheetJSONString();
if (json === '') {
await fetch('/api/spreadsheets/123/content', { method: 'PUT', body: await spreadsheet.saveSpreadsheet() });
} else {
await fetch('/api/spreadsheets/123', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title: 'Q3 forecast', content: json }),
});
}

export(config): Promise<ArrayBuffer>

Exports a snapshot of the spreadsheet in the specified format.

Requires the Spreadsheet Editing component in the license key, and an .xlsx export also requires XLSX Support. In evaluation mode, a PDF export carries a watermark on every page, and an .xlsx export carries one on every sheet, both as its background and in its printed header.

A PDF export that names no sheet prints every visible sheet and skips hidden ones. A hidden sheet named by sheet is still printed.

ExportSpreadsheetConfig

Promise<ArrayBuffer>

// Hand the user an .xlsx to download
const xlsx = await spreadsheet.export({ format: 'xlsx' });
const link = document.createElement('a');
link.href = URL.createObjectURL(
new Blob([xlsx], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }),
);
link.download = 'quarterly.xlsx';
link.click();
URL.revokeObjectURL(link.href);
// Every visible sheet as one PDF; pass `sheet` for one of them, by 0-based index
const pdf = await spreadsheet.export({ format: 'pdf' });

ExportSpreadsheetConfig


docAuthSystem(): DocAuthSystem

The system this spreadsheet was opened by.

DocAuthSystem