Style
Manage the cell style using the following methods.
Documentation
Methods
Available methods for cell style management.
Method | Description |
---|---|
getStyle | Get the style information from one or more cells. @param cellNames - cell names and/or ranges. If omitted, returns styles for all cells. Jspreadsheet getStyle(cellNames?: string): Promise<{ [cellName: string]: string }> GET /api/:guid/style |
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. Jspreadsheet setStyle(styles: { cellName: string; value: string }[]): Promise<void> POST /api/:guid/style |
removeStyle | Remove all styles from one or more cells. @param cellNames - cell names and/or ranges. Jspreadsheet removeStyle(cellNames: string): Promise<void> DELETE /api/:guid/style |
Examples
Set style
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);
// New styles
const styles = [
{
cellName: "A1",
value: "background-color: #333;color:#fff;",
},
{
cellName: "A2",
value: "background-color: #ccc",
},
];
// Apply style
spreadsheet.setStyle(styles).then(() => {
// It worked correctly
}).catch((err) => {
console.log(err);
});
Reset style
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);
// Reset A1,A2,A3 or A1:A3 for multiple cells
spreadsheet.removeStyle("A1").then(() => {
// It worked correctly
}).catch((err) => {
// Something went wrong
console.log(err);
});