This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/document-authoring/spreadsheets/save-and-export.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Save and export spreadsheets

Use saveSpreadsheet() to store a spreadsheet and reopen it later. Use export() to create an XLSX or PDF file for other apps or users.

Before you start, install and run the Document Authoring library in your app. If you haven’t set it up, refer to the getting started guide.

The examples omit error handling. Add it before you use this code in production.

Before saving or exporting, get the spreadsheet from the editor with currentSpreadsheet().

const spreadsheet = editor.currentSpreadsheet();

Save as SheetJSON

SheetJSON is Document Authoring’s native spreadsheet format. Save a spreadsheet as SheetJSON. Then reopen it with loadSpreadsheet() to preserve all supported data. Use SheetJSON as your working copy, and export to XLSX only when another app needs the spreadsheet.

Treat SheetJSON as an opaque file. Store and load it, but don’t read or change its contents in your code, because its structure can change between releases. For a minimal example, refer to the SheetJSON guide.

saveSpreadsheet() returns a Blob and supports spreadsheets of any size. Document Authoring writes large spreadsheets in parts:

const saved = await spreadsheet.saveSpreadsheet();
await fetch('/api/spreadsheets/123', { method: 'PUT', body: saved });

To reopen a saved spreadsheet, refer to the import and load guide.

Save as a JSON string

saveSpreadsheetJSONString() returns the same content as a string for APIs that expect JSON. A very large spreadsheet might not fit in a JavaScript string. The method returns an empty string in that case. Handle this 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 }),
});
}

Save on a timer

The spreadsheet editor doesn’t emit change events. To save automatically, save on a timer or when the user leaves the view:

const saveInterval = setInterval(async () => {
const saved = await editor.currentSpreadsheet().saveSpreadsheet();
await fetch('/api/spreadsheets/123', { method: 'PUT', body: saved });
}, 60_000);

Stop the timer when you remove the editor:

clearInterval(saveInterval);
editor.destroy();

Export to XLSX

Pass format: 'xlsx' to export an XLSX file:

const xlsx = await spreadsheet.export({ format: 'xlsx' });

Document Authoring creates a new XLSX file from its spreadsheet model instead of copying the original file. The exported file omits unsupported content, such as charts, images, and conditional formatting.

Export to PDF

Pass format: 'pdf' to export a PDF. By default, the PDF includes every visible sheet in order:

const pdf = await spreadsheet.export({ format: 'pdf' });

To export one sheet, pass its zero-based index in sheet. To export the sheet the user is viewing, pass activeSheet():

const pdf = await editor.currentSpreadsheet().export({
format: 'pdf',
sheet: editor.activeSheet(),
});

A hidden sheet exports only when you pass its index. If no sheet has that index, export() rejects.

The PDF uses each sheet’s page setup, including paper size, orientation, scale, fit to page, margins, centering, and row and column headings. Users set these options in the editor’s Page setup menu. The spreadsheet stores the page setup.

Download an exported file

export() returns an ArrayBuffer, not a downloaded file. To save the result on the user’s device, wrap the bytes in a Blob, create an object URL, and click a temporary link:

const pdf = await editor.currentSpreadsheet().export({ format: 'pdf' });
const url = URL.createObjectURL(new Blob([pdf], { type: 'application/pdf' }));
const link = document.createElement('a');
link.href = url;
link.download = 'quarterly.pdf';
link.click();
URL.revokeObjectURL(url);

For XLSX output, pass format: 'xlsx' and use a file name ending in .xlsx.

The editor’s toolbar download menu names files spreadsheet.pdf or spreadsheet.xlsx. Its PDF option exports only the current sheet. To choose a file name or export every sheet, add a download button with the code above.

Learn more

Import and load
Reopen saved spreadsheets and import XLSX files.

Spreadsheets in Node.js
Export spreadsheets on a server.