Tables

Manage the data tables of your online spreadsheets using the following routes. Tables require Jspreadsheet version 13.

Documentation

getTable

Get all tables of the worksheet, or one table by its name.

Parameter Description
name Table name. Without it, every table of the worksheet is returned.

GET /api/:guid/:worksheetIndex/table

GET /api/:guid/:worksheetIndex/table/:name

setTable

Create a table over a range, or replace the table with the same name. Table names are unique across the workbook, and tables follow inserts, deletes and moves of rows and columns.

Parameter Description
data.name Table name, unique across the workbook.
data.range Cell range of the table, such as A1:D10.
data.headerRow The first row of the range holds the column names. Default false: the first row is data and the names come from headers.
data.headers Column names. Missing names default to Column1, Column2, ...
data.filters Show the column filters.
data.totalRow Show the total row.
data.bandedRows Alternate the row colours.
data.bandedColumns Alternate the column colours.
data.theme Table style.

data can also be an array of table configurations.

POST /api/:guid/:worksheetIndex/table

resetTable

Remove the formatting and the filters of a table. The cell values stay.

Parameter Description
name Table name.

DELETE /api/:guid/:worksheetIndex/table/:name

Examples

Create a table

const baseUrl = 'http://localhost:8009/api';
const guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
const token = 'eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i';
const headers = { 'Authorization': `Bearer ${token}` };

// A table with a header row, filters and banded rows
await fetch(`${baseUrl}/${guid}/0/table`, {
    method: 'POST',
    headers,
    body: new URLSearchParams({
        'data': JSON.stringify({
            name: 'Sales',
            range: 'A1:D10',
            headerRow: true,
            filters: true,
            bandedRows: true,
        }),
    }),
});

Read the tables

// Every table of the first worksheet
const tables = await (await fetch(`${baseUrl}/${guid}/0/table`, { headers })).json();

// One table by name
const sales = await (await fetch(`${baseUrl}/${guid}/0/table/Sales`, { headers })).json();

Remove a table

await fetch(`${baseUrl}/${guid}/0/table/Sales`, {
    method: 'DELETE',
    headers,
});