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 worksheets programmatically.
| Method | Description |
|---|---|
| createWorksheet | Create a new worksheet. @param options - worksheet options. Jspreadsheet createWorksheet(options: Partial<Worksheet> & { worksheetName: string; }, index?: number): Promise<IJworksheet> POST /api/:guid/worksheet |
| renameWorksheet | Rename the worksheet. @param worksheet - worksheet position @param newValue - new title Jspreadsheet renameWorksheet(worksheet: number, newValue: string): Promise<void> POST /api/:guid/worksheet/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/worksheet/move |
| deleteWorksheet | Delete a worksheet by its position. @param worksheetPosition - worksheet position. Jspreadsheet deleteWorksheet(worksheetPosition: number): Promise<void> DELETE /api/:guid/worksheet/:worksheetPosition |
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 = { worksheetName: "New worksheet", minDimensions: [10, 10],};
// Resultspreadsheet.createWorksheet(options).then(async (newWorksheet) => { console.log(await newWorksheet.getConfig());});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] } }'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);});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" }'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, 0).then(() => { // It worked correctly}).catch((err) => { console.log(err);});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 }'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);});curl -X DELETE "http://localhost:8009/api/15eb1171-5a64-45bf-be96-f52b6125a045/worksheet/0" \ -H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i"