Skip to content
TREB Docs

Documents

TREB documents (spreadsheet files) use a simple JSON format. TREB can read and write XLSX files as well, but XLSX files are very large and slow to read and write (because they’re zipped).

Loading a document

Using HTML tags

If you are embedding a spreadsheet using HTML tags, you can load a document using the document attribute:

<treb-spreadsheet document="/path/to/document.treb.json" />
<treb-spreadsheet document="/path/to/document.treb.json" />

This will load the named document when the spreadsheet is created. Documents are loaded using fetch, so if the document is on another web server you must make sure that CORS headers are set appropriately.

Using the API

If you are using the API, there are a couple of ways to load a document. You can load it when you create the spreadsheet, by setting the document option:

import { TREB } from '@trebco/treb';
TREB.CreateSpreadsheet({
container: element,
document: '/path/to/document.treb.json'
});
import { TREB } from '@trebco/treb';
TREB.CreateSpreadsheet({
container: element,
document: '/path/to/document.treb.json'
});

You can also load a document using the API method after a spreadsheet is created. You can load a remote document using LoadNetworkDocument:

import { TREB } from '@trebco/treb';
const sheet = TREB.CreateSpreadsheet({
container: element,
});
// ...
sheet.LoadNetworkDocument('/path/to/document.treb.json');
import { TREB } from '@trebco/treb';
const sheet = TREB.CreateSpreadsheet({
container: element,
});
// ...
sheet.LoadNetworkDocument('/path/to/document.treb.json');

Or if you have the document in memory, from another source, you can load it directly as a javascript object or JSON string with LoadDocument:

// ...
sheet.LoadDocument(doc);
// ...
sheet.LoadDocument(doc);

Converting XLSX files

Any TREB spreadsheet can read XLSX files and save documents in the TREB JSON format. You can do it with the API, or if the apporpriate options are set you can use the toolbar or drag-and-drop files.

You can use the one below. The file menu is on the left-hand side of the toolbar; or you can drag-and-drop XLSX files right onto the spreadsheet.

To save the file as a TREB JSON file, use the file menu.