Worksheets
Programmatically changes on the worksheet level are available through the following operations.
Documentation
Section titled “Documentation”Methods
Section titled “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
Section titled “Examples”Create a new worksheet
Section titled “Create a new worksheet”The worksheet position and unique-id is returned.
import { Client } from "@intrasheets/client";
// Create a new clientconst client = new Client({ // API Server baseUrl: "http://localhost:8009/api", // Your authentication token token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",});
// Spreadsheet Guidconst guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Options for the new worksheet @See Jspreadsheet documentation for more optionsconst options = { minDimensions: [10, 10],};
// Resultspreadsheet.createWorksheet().then((newWorksheet) => { console.log(newWorksheet);});
// {// worksheet: 1,// worksheetId: "c216d2cd"// }Rename worksheet
Section titled “Rename worksheet”How to rename a remote worksheet.
import { Client } from "@intrasheets/client";
// Create a new clientconst client = new Client({ // API Server baseUrl: "http://localhost:8009/api", // Your authentication token token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",});
// Spreadsheet Guidconst guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Rename the first worksheetspreadsheet.renameWorksheet(0, "New title for the first worksheet").then(() => { // It worked correctly}).catch((err) => { // Something went wrong console.log(err);});Update worksheet position
Section titled “Update worksheet position”How to change the worksheet order on a remote spreadsheet.
import { Client } from "@intrasheets/client";
// Create a new clientconst client = new Client({ // API Server baseUrl: "http://localhost:8009/api", // Your authentication token token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",});
// Spreadsheet Guidconst guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Update the second worksheet to the third positionspreadsheet.moveWorksheet(1, 2).then(() => { // It worked correctly}).catch((err) => { console.log(err);});Delete worksheet
Section titled “Delete worksheet”How to delete a remote worksheet.
import { Client } from "@intrasheets/client";
// Create a new clientconst client = new Client({ // API Server baseUrl: "http://localhost:8009/api", // Your authentication token token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",});
// Spreadsheet Guidconst guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Delete the first worksheetspreadsheet.deleteWorksheet(0).then(() => { // It worked correctly}).catch((err) => { // Something went wrong console.log(err);});Set worksheet
Section titled “Set worksheet”Change the default worksheet in the client.
import { Client } from "@intrasheets/client";
// Create a new clientconst client = new Client({ // API Server baseUrl: "http://localhost:8009/api", // Your authentication token token: "eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i",});
// Spreadsheet Guidconst guid = '15eb1171-5a64-45bf-be96-f52b6125a045';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Get data from worksheet 0spreadsheet.getData().then((result) => { console.log(result);});
// Change the worksheet being usedspreadsheet.setWorksheet(1);
// Get data from worksheet 1spreadsheet.getData().then((result) => { console.log(result);});