Style
Manage the cell style using the following methods.
Documentation
Section titled “Documentation”Methods
Section titled “Methods”Available methods for cell style management.
| Method | Description |
|---|---|
| getStyle | Get the style information from one or more cells. @param cellNames - cell name. If omitted, returns styles for all cells. @param index - return the cell's style index or its style. Jworksheet getStyle(cellNames?: string | null, index?: boolean): Promise<{ [cellName: string]: string | number } | null>; GET /api/:guid/:worksheetIndex/style/:cellName |
| setStyle | Apply or remove styles from one or more cells @param styles[].cellName - name of the cell to be styled. @param styles[].value - new cell styles. If a style property is sent without a value (with just blank spaces), it will be removed. @param overwrite - If true, removes all current styles from cells before applying new ones. Jworksheet setStyle(styles: { cellName: string; value: string | number; }[], overwrite?: boolean): Promise<void> POST /api/:guid/:worksheetIndex/style |
| removeStyle | Remove all styles from one or more cells. @param cellNames - Comma-separated cell names. Jworksheet removeStyle(cellNames: string): Promise<void> DELETE /api/:guid/:worksheetIndex/style/:cellName |
Examples
Section titled “Examples”Set style
Section titled “Set style”Define style to the spreadsheet cells.
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 = '79b45919-c751-4e2b-a49a-6c1286e2fc03';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Get Jworksheet objectconst worksheet = spreadsheet.getWorksheet(0);
// New stylesconst styles = [ { cellName: "A1", value: "background-color: #333;color:#fff;", }, { cellName: "A2", value: "background-color: #ccc", },];
// Apply styleworksheet .setStyle(styles) .then(() => { // It worked correctly }) .catch((err) => { console.log(err); });curl -X POST "http://localhost:8009/api/79b45919-c751-4e2b-a49a-6c1286e2fc03/0/style" \ -H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i" \ -H "Content-Type: application/json" \ -d '{ "styles": [ { "cellName": "A1", "value": "background-color: #333;color:#fff;" }, { "cellName": "A2", "value": "background-color: #ccc" } ], "overwrite": true }'Reset style
Section titled “Reset style”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 = '79b45919-c751-4e2b-a49a-6c1286e2fc03';
// Get the spreadsheet instanceconst spreadsheet = client.getSpreadsheet(guid);
// Get Jworksheet objectconst worksheet = spreadsheet.getWorksheet(0);
// Reset A1,A2,A3 for multiple cellsworksheet .removeStyle("A1") .then(() => { // It worked correctly }) .catch((err) => { // Something went wrong console.log(err); });curl -X DELETE "http://localhost:8009/api/79b45919-c751-4e2b-a49a-6c1286e2fc03/0/style/A1" \ -H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i"