Worksheets
Programmatically changes on the worksheet level are available through the following operations.
Documentation
Methods
The following methods are available to interact with the spreadsheet headers programmatically.
Method | Description |
---|---|
createWorksheet | Create a new worksheet. @param options - worksheet options. Jspreadsheet createWorksheet(options?: Partial<Worksheet>): Promise<{ worksheet: number; worksheetId: string }> POST /api/:guid/worksheets |
renameWorksheet | Rename the worksheet. @param worksheet - worksheet position @param newValue - new title Jspreadsheet renameWorksheet(worksheet: number, newValue: string): Promise<void> POST /api/:guid/worksheets/rename |
moveWorksheet | Move a worksheet position. @param from - worksheet position. @param to - new position. Jspreadsheet moveWorksheet(from: number, to: number): Promise<void> POST /api/:guid/worksheets/move |
deleteWorksheet | Delete a worksheet by its position. @param worksheetPosition - worksheet position. Jspreadsheet deleteWorksheet(worksheetPosition: number): Promise<void> DELETE /api/:guid/worksheets/:worksheetPosition |
setWorksheet | Change the worksheet being used by the client api. @param worksheetIndex - worksheet position. Jspreadsheet setWorksheet(worksheetIndex: number): void |
Examples
Create a new worksheet
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 = {
minDimensions: [10, 10],
};
// Result
spreadsheet.createWorksheet().then((newWorksheet) => {
console.log(newWorksheet);
});
// {
// worksheet: 1,
// worksheetId: "c216d2cd"
// }
Rename worksheet
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);
});
Update worksheet position
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, 2).then(() => {
// It worked correctly
})
.catch((err) => {
console.log(err);
});
Delete worksheet
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);
});
Set worksheet
Change the default worksheet in the client.
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);
// Get data from worksheet 0
spreadsheet.getData().then((result) => {
console.log(result);
});
// Change the worksheet being used
spreadsheet.setWorksheet(1);
// Get data from worksheet 1
spreadsheet.getData().then((result) => {
console.log(result);
});