# Loading and Saving Workbooks

> Load and save XLSX, ODS, TXWB, PDF, CSV, XML and JSON with load, save and saveText: stream types, load warnings, string output, download of bytes and failures.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Sheet Control > Document Processing > Loading and Saving Workbooks
- **1420 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/document-processing/load-save/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/document-processing/load-save/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/document-processing/load-save/llms-full.txt

---

TX Sheet Control loads and saves workbooks through a public dispatcher, `load` and `save`, and a stream type that selects the file format. Use this dispatcher rather than calling undocumented format helpers. A filename extension alone is not the API's format selector.

What follows covers the seven formats, loading and saving in the browser editor, string output for tabular data, the delivery of the saved bytes and the handling of options and failures.

### Supported Formats

| Format | Stream type | Read | Write | Typical use |
|---|---|---|---|---|
| XLSX | `SpreadsheetML` | Yes | Yes | Exchange spreadsheet documents with Excel-compatible applications |
| ODS | `OpenDocumentSpreadsheet` | Yes | Yes | Exchange OpenDocument workbooks and retain original package content |
| TXWB | `InternalWorkbookFormat` | Yes | Yes | Retain TX Sheet Control views, dashboards and report metadata |
| PDF | `PDF` | No | Yes | Deliver fixed-page output |
| CSV | `CSV` | Yes | Yes | Exchange one worksheet as UTF-8 delimited values |
| XML | `XML` | Yes | Yes | Exchange tabular rows and scalar fields |
| JSON | `JSON` | Yes | Yes | Exchange record arrays or positional row arrays |

The stream types are the values of the [StreamType](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/streamtype/llms-full.txt) enumeration. The CSV, XML and JSON APIs transfer values, not full workbook features. [CSV, XML and JSON Data](https://docs.textcontrol.com/tx-sheet-control/document-processing/tabular-data/llms-full.txt) has complete examples, the supported schemas and the import and export settings of these three formats.

### Load and Save a Workbook

The following code loads an XLSX file into the browser editor and saves the workbook as XLSX, TXWB and PDF. `editor` is the [Spreadsheet](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/llms-full.txt) of the browser editor, created as in [JavaScript](https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/javascript/llms-full.txt), and `file` is the XLSX file to load, such as an upload:

```javascript
const bytes = new Uint8Array(await file.arrayBuffer());
const result = await editor.load(bytes, StreamType.SpreadsheetML);

for (const warning of result.warnings) console.warn(warning);

const xlsx = await editor.save(StreamType.SpreadsheetML);
const txwb = await editor.save(StreamType.InternalWorkbookFormat);
const pdf = await editor.save(StreamType.PDF);
```

The code works as follows:

- [load](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/load-method/llms-full.txt) reads the bytes as XLSX, which `StreamType.SpreadsheetML` selects, and returns a [LoadResult](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/loadresult/llms-full.txt). Its `warnings` are the import notices of the conversion, which the loop writes to the console.
- [save](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/save-method/llms-full.txt) returns the bytes of the workbook in the format of the stream type: XLSX, TXWB or PDF.

TXWB is a workbook archive, not an arbitrary JSON file. Loading raw JSON under the `InternalWorkbookFormat` stream type is rejected.

> Important
>
> **Handles After Loading.** Loading replaces the document and invalidates old handles. Reacquire sheets and ranges after a successful load.

### OpenDocument Spreadsheet

Use `StreamType.OpenDocumentSpreadsheet` with the same byte-based load and save methods in JavaScript, TypeScript, Angular, ASP.NET Core, Node.js and .NET. [OpenDocument Spreadsheet](https://docs.textcontrol.com/tx-sheet-control/document-processing/ods/llms-full.txt) explains preservation, format settings and examples.

### Save CSV, XML or JSON as a String

For CSV, XML and JSON, you can get a string directly instead of bytes: call `await editor.saveText(StreamType.CSV, options)` with [saveText](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/savetext-method/llms-full.txt) in JavaScript, or `await control.SaveTextAsync(StreamType.CSV, options)` with [SaveTextAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/savetextasync-method/llms-full.txt) in .NET.

The worksheet and range settings, cancellation, save events and UTF-8 byte limits are the same as for byte export. A generated CSV BOM is omitted from strings.

[Save Tabular Content as a String](https://docs.textcontrol.com/tx-sheet-control/document-processing/tabular-data/#save-tabular-content-as-a-string) shows both methods with their settings.

### Deliver the Bytes

How the saved bytes reach their destination depends on where your code runs:

- **In a browser**, create a `Blob` with the appropriate MIME type and offer it through an object URL or a download link, then revoke the URL.
- **In .NET**, use the file, stream or byte overloads of [SaveAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/saveasync-method/llms-full.txt).
- **In Node.js**, write the returned bytes or send them through an authorized response.

File dialogs, storage names and access permissions are the responsibilities of your application.

### Set Options and Handle Failures

Use the `LoadOptions` and `SaveOptions` of your package for size limits, format-specific settings, metadata and cancellation, for example [LoadOptions](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/loadoptions/llms-full.txt) and [SaveOptions](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/saveoptions/llms-full.txt) in the browser editor.

Inspect the warnings and handle rejected tasks and promises. Do not show a success message before the bytes are available. A failed or canceled operation does not emit a successful loaded or saved notification.

### Next Steps

- [CSV, XML and JSON Data](https://docs.textcontrol.com/tx-sheet-control/document-processing/tabular-data/llms-full.txt): exchange the values of one worksheet with other applications.
- [XLSX Compatibility](https://docs.textcontrol.com/tx-sheet-control/document-processing/xlsx-compatibility/llms-full.txt): check how an Excel workbook survives loading and saving.
- [Exporting Worksheets to PDF](https://docs.textcontrol.com/tx-sheet-control/pdf/export/llms-full.txt): create the fixed-page PDF output.
- [Document Properties](https://docs.textcontrol.com/tx-sheet-control/document-processing/properties/llms-full.txt): set the metadata of the documents you save.
- [Events and Cancellation](https://docs.textcontrol.com/tx-sheet-control/spreadsheet-editor/events/llms-full.txt): react to loading and saving, and cancel them.

---

## Nearby

- **Previous:** [Document Processing](https://docs.textcontrol.com/tx-sheet-control/document-processing/llms-full.txt)
- **Next:** [CSV, XML and JSON Data](https://docs.textcontrol.com/tx-sheet-control/document-processing/tabular-data/llms-full.txt)
