Skip to content

Worksheets

Programmatically changes on the worksheet level are available through the following operations.

The following methods are available to interact with the spreadsheet worksheets programmatically.

MethodDescription
createWorksheetCreate a new worksheet.
@param options - worksheet options.

Jspreadsheet createWorksheet(options: Partial<Worksheet> & { worksheetName: string; }, index?: number): Promise<IJworksheet>

POST /api/:guid/worksheet
renameWorksheetRename the worksheet.
@param worksheet - worksheet position
@param newValue - new title

Jspreadsheet renameWorksheet(worksheet: number, newValue: string): Promise<void>

POST /api/:guid/worksheet/rename
moveWorksheetMove a worksheet position.
@param from - worksheet position.
@param to - new position.

Jspreadsheet moveWorksheet(from: number, to: number): Promise<void>

POST /api/:guid/worksheet/move
deleteWorksheetDelete a worksheet by its position.
@param worksheetPosition - worksheet position.

Jspreadsheet deleteWorksheet(worksheetPosition: number): Promise<void>

DELETE /api/:guid/worksheet/:worksheetPosition

The worksheet position and unique-id is returned.

import { Client } from "@intrasheets/client";
// Create a new client
const client = new Client({
// API Server
baseUrl: "http://localhost:8009/api",
// Your authentication token
token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",
});
// Spreadsheet Guid
const guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);
// Options for the new worksheet @See Jspreadsheet documentation for more options
const options = {
worksheetName: "New worksheet",
minDimensions: [10, 10],
};
// Result
spreadsheet.createWorksheet(options).then(async (newWorksheet) => {
console.log(await newWorksheet.getConfig());
});
Terminal window
curl -X POST "http://localhost:8009/api/15eb1171-5a64-45bf-be96-f52b6125a045/worksheet" \
-H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i" \
-H "Content-Type: application/json" \
-d '{
"options": {
"worksheetName": "New worksheet",
"minDimensions": [10, 10]
}
}'

How to rename a remote worksheet.

import { Client } from "@intrasheets/client";
// Create a new client
const client = new Client({
// API Server
baseUrl: "http://localhost:8009/api",
// Your authentication token
token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",
});
// Spreadsheet Guid
const guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);
// Rename the first worksheet
spreadsheet.renameWorksheet(0, "New title for the first worksheet").then(() => {
// It worked correctly
})
.catch((err) => {
// Something went wrong
console.log(err);
});
Terminal window
curl -X POST "http://localhost:8009/api/15eb1171-5a64-45bf-be96-f52b6125a045/worksheet/rename" \
-H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i" \
-H "Content-Type: application/json" \
-d '{
"worksheet": 0,
"newValue": "New title for the first worksheet"
}'

How to change the worksheet order on a remote spreadsheet.

import { Client } from "@intrasheets/client";
// Create a new client
const client = new Client({
// API Server
baseUrl: "http://localhost:8009/api",
// Your authentication token
token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",
});
// Spreadsheet Guid
const guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);
// Update the second worksheet to the third position
spreadsheet.moveWorksheet(1, 0).then(() => {
// It worked correctly
})
.catch((err) => {
console.log(err);
});
Terminal window
curl -X POST "http://localhost:8009/api/15eb1171-5a64-45bf-be96-f52b6125a045/worksheet/move" \
-H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i" \
-H "Content-Type: application/json" \
-d '{
"from": 1,
"to": 0
}'

How to delete a remote worksheet.

import { Client } from "@intrasheets/client";
// Create a new client
const client = new Client({
// API Server
baseUrl: "http://localhost:8009/api",
// Your authentication token
token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",
});
// Spreadsheet Guid
const guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);
// Delete the first worksheet
spreadsheet.deleteWorksheet(0).then(() => {
// It worked correctly
})
.catch((err) => {
// Something went wrong
console.log(err);
});
Terminal window
curl -X DELETE "http://localhost:8009/api/15eb1171-5a64-45bf-be96-f52b6125a045/worksheet/0" \
-H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i"