Skip to content

Style

Manage the cell style using the following methods.

Available methods for cell style management.

MethodDescription
getStyleGet 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
setStyleApply 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
removeStyleRemove 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

Define style to the spreadsheet cells.

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 = '79b45919-c751-4e2b-a49a-6c1286e2fc03';
// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);
// Get Jworksheet object
const worksheet = spreadsheet.getWorksheet(0);
// New styles
const styles = [
{
cellName: "A1",
value: "background-color: #333;color:#fff;",
},
{
cellName: "A2",
value: "background-color: #ccc",
},
];
// Apply style
worksheet
.setStyle(styles)
.then(() => {
// It worked correctly
})
.catch((err) => {
console.log(err);
});
Terminal window
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
}'
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 = '79b45919-c751-4e2b-a49a-6c1286e2fc03';
// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);
// Get Jworksheet object
const worksheet = spreadsheet.getWorksheet(0);
// Reset A1,A2,A3 for multiple cells
worksheet
.removeStyle("A1")
.then(() => {
// It worked correctly
})
.catch((err) => {
// Something went wrong
console.log(err);
});
Terminal window
curl -X DELETE "http://localhost:8009/api/79b45919-c751-4e2b-a49a-6c1286e2fc03/0/style/A1" \
-H "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCJ9.eyJkb21haW4iOiJsb2NhbGhvc3Q6ODAPQSJ9.Xr2Ir2-zEc_tqV5y6i"