---
title: "Save and export spreadsheets"
canonical_url: "https://www.nutrient.io/guides/document-authoring/spreadsheets/save-and-export/"
md_url: "https://www.nutrient.io/guides/document-authoring/spreadsheets/save-and-export.md"
last_updated: "2026-10-29T00:00:00.000Z"
description: "Save Document Authoring spreadsheets as SheetJSON, and export them to XLSX and PDF files."
---

# Save and export spreadsheets

Use [`saveSpreadsheet()`](https://www.nutrient.io/api/document-authoring/types/docauthspreadsheet/#savespreadsheet) to store a spreadsheet and reopen it later. Use [`export()`](https://www.nutrient.io/api/document-authoring/types/docauthspreadsheet/#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](https://www.nutrient.io/guides/document-authoring/spreadsheets/getting-started.md) 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()`](https://www.nutrient.io/api/document-authoring/types/docauthspreadsheeteditor/#currentspreadsheet).

```js

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()`](https://www.nutrient.io/api/document-authoring/types/docauthsystem/#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](https://www.nutrient.io/guides/document-authoring/spreadsheets/sheetjson.md) guide.

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

```js

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](https://www.nutrient.io/guides/document-authoring/spreadsheets/import-and-load.md) guide.

### Save as a JSON string

[`saveSpreadsheetJSONString()`](https://www.nutrient.io/api/document-authoring/types/docauthspreadsheet/#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:

```js

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:

```js

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:

```js

clearInterval(saveInterval);
editor.destroy();

```

## Export to XLSX

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

```js

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:

```js

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()`](https://www.nutrient.io/api/document-authoring/types/docauthspreadsheeteditor/#activesheet):

```js

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:

```js

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](https://www.nutrient.io/guides/document-authoring/spreadsheets/import-and-load.md)**\
Reopen saved spreadsheets and import XLSX files.

**[Spreadsheets in Node.js](https://www.nutrient.io/guides/document-authoring/spreadsheets/nodejs.md)**\
Export spreadsheets on a server.
---

## Related pages

- [Spreadsheets](/guides/document-authoring/spreadsheets.md)
- [Spreadsheet editor](/guides/document-authoring/spreadsheets/editor.md)
- [Spreadsheet formulas](/guides/document-authoring/spreadsheets/formulas.md)
- [Get started with spreadsheets](/guides/document-authoring/spreadsheets/getting-started.md)
- [Import and load spreadsheets](/guides/document-authoring/spreadsheets/import-and-load.md)
- [Spreadsheets in Node.js](/guides/document-authoring/spreadsheets/nodejs.md)
- [Spreadsheet JSON support with SheetJSON](/guides/document-authoring/spreadsheets/sheetjson.md)

