Style

Manage the cell style using the following methods.

Documentation

Methods

Available methods for cell comments management.
MethodDescription
getStyle Get the style information from one or more cells.
getStyle(cellNames?: string): Promise<{ [cellName: string]: string }>
@param cellNames - cell names and/or ranges. If omitted, returns styles for all cells.

GET /api/:guid/style
setStyle Apply or remove styles from one or more cells
setStyle(styles: { cellName: string; value: string }[]): Promise<void>
@param styles[].cellName - name of the cell to be styled.
@param styles[].value - new cell styles.

POST /api/:guid/style
removeStyle Remove all styles from one or more cells.
removeStyle(cellNames: string): Promise<void>
@param cellNames - cell names and/or ranges.

DELETE /api/:guid/style


Examples


Set style

Define style to the spreadsheet cells.

NodeJS
PHP
import { Client } from '@jspreadsheet/client';

// Access token
const token = 'MSxlMjE2MWI5YWNjYTg2MzM4MThmN2Y4NjY0YmQzYzBlOGExMmVkZjVk';

// Spreadsheet Guid
const guid = '79b45919-c751-4e2b-a49a-6c1286e2fc03';

// Create a new client
const client = new Client(token);

// 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);
    });
<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSxlMjE2MWI5YWNjYTg2MzM4MThmN2Y4NjY0YmQzYzBlOGExMmVkZjVk';

// Spreadsheet Guid
$guid = '79b45919-c751-4e2b-a49a-6c1286e2fc03';

// Create a new client
$client = new Jspreadsheet($token);

// Get the spreadsheet instance
$spreadsheet = $client->getSpreadsheet($guid);

$styles = [
    'A1' => 'background-color: #333;color:#fff;',
    'A2' => 'background-color: #ccc'
];

// Apply style
$result = $spreadsheet->setStyle($styles);

// Result
print_r($result);

// {"success":1,"message":"Updated"}

Get style

Retrieving the style of a cell

NodeJS
PHP

<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSxlMjE2MWI5YWNjYTg2MzM4MThmN2Y4NjY0YmQzYzBlOGExMmVkZjVk';

// Spreadsheet Guid
$guid = '79b45919-c751-4e2b-a49a-6c1286e2fc03';

// Create a new client
$client = new Jspreadsheet($token);

// Get the spreadsheet instance
$spreadsheet = $client->getSpreadsheet($guid, 0); // Zero for the first worksheet, 1 for the second, etc.

// Get style
$result = $spreadsheet->getStyle('A1'); // Array for multiple requests

// Result
print_r($result);

// {"A1":"background-color: #333;color:#fff"}

Reset style


NodeJS
PHP
import { Client } from '@jspreadsheet/client';

// Access token
const token = 'MSxlMjE2MWI5YWNjYTg2MzM4MThmN2Y4NjY0YmQzYzBlOGExMmVkZjVk';

// Spreadsheet Guid
const guid = '79b45919-c751-4e2b-a49a-6c1286e2fc03';

// Create a new client
const client = new Client(token);

// 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);
});
<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSxlMjE2MWI5YWNjYTg2MzM4MThmN2Y4NjY0YmQzYzBlOGExMmVkZjVk';

// Spreadsheet Guid
$guid = '79b45919-c751-4e2b-a49a-6c1286e2fc03';

// Create a new client
$client = new Jspreadsheet($token);

// Get the spreadsheet instance
$spreadsheet = $client->getSpreadsheet($guid);

// Reset
$result = $spreadsheet->resetStyle('A1');

// Result
print_r($result);

// {"success":1,"message":"Updated"}



Create applications with spreadsheet-like controls