Jspreadsheet is constructed using real DOM elements, which allows you to apply CSS directly to the cells. However, when you use external styling, there is no internal tracking, history, or persistence. Therefore, Jspreadsheet offers settings and methods to manage the internal style programmatically.
What is new Jspreadsheet now features a global style property at the spreadsheet level, enabling the reuse of styles across different worksheets and cells. Additionally, the latest version allows for the application of CSS styles to entire rows or columns through Excel-like syntax, such as A:A or 1:1.
Documentation
Methods
You can manage the spreadsheet cell style with the following methods.
Method
Description
getStyle
Get style from one or multiple cells. @param {string|null} - Cell identification or null for the whole table. @param {boolean?} - Return the indexes of the global style. getStyle(cellName: String | null, onlyIndexes?: Boolean)
setStyle
Set a single cell style by name, or set the style for multiple cells. @param {String|Object} - ID of a cell or an object with multiple cells and the style definitions. @param {String?} property - Style property @param {String?} value - Style value @param {Boolean?} forceOverwrite - true to overwrite the existing CSS. setStyle: (cell: string | object, property?: string, value?: string, forceOverwrite?: boolean) => void;
resetStyle
Reset the style for one or multiple cells @param {string|string[]} - String to identify a cell or an array of cell identifications (A1, A2... etc) resetStyle(cellName: String | String[])
Events
Spreadsheet style related events.
Event
Description
onchangestyle
onchangestyle(worksheet: Object, newValue: Object, oldValue: Objectd) : void The method will return an object with the cells and the properties applied.
Initial Settings
The following property is available through the initialization of the online spreadsheet.
Property
Description
Worksheet level
style: object
Each object property corresponds to a cell name and range, with the value representing either a CSS string or ID for the global style.
Spreadsheet level
style: string[]
The global style definition is an array of CSS strings to generate the CSS classes that will be used across all worksheets.
Examples
Style in the worksheet level
Create a data grid with the style definitions on the worksheet level.
Sheet1
Search:
A
B
C
D
E
F
G
H
1
2
3
4
<html><scriptsrc="https://jspreadsheet.com/v10/jspreadsheet.js"></script><scriptsrc="https://jsuites.net/v5/jsuites.js"></script><linkrel="stylesheet"href="https://jspreadsheet.com/v10/jspreadsheet.css"type="text/css" /><linkrel="stylesheet"href="https://jsuites.net/v5/jsuites.css"type="text/css" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Material+Icons" /><divid="spreadsheet"></div><script>// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('Y2JjY2E5Yjk5Y2EyMzIxMDE4NGFkZmRhZmE5ZDdmM2RhYWQ2YTJkYzdmM2EwOGE1NWMyYjg2MGRhNzIzNGRiN2U0ZDVmYjY1OWMwZTU5ODMwOWVjMzI4Mzk3NzNkMzgwYjEyN2IyMmZiYmVkODdhYjU2OGU0OWZmNDAxNWVlMWUsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpRME1Ea3hOREE1TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==');
// Create the spreadsheetjspreadsheet(document.getElementById('spreadsheet'), {
worksheets: [{
minDimensions: [8,4],
style: {
'C:C': 'background-color: #ccffff; font-weight: bold',
'E1': 'background-color: #ccffff;',
},
}]
});
</script></html>
import { Component, ViewChild, ElementRef } from"@angular/core";
import jspreadsheet from"jspreadsheet";
import"jspreadsheet/dist/jspreadsheet.css"import"jsuites/dist/jsuites.css"// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('Y2JjY2E5Yjk5Y2EyMzIxMDE4NGFkZmRhZmE5ZDdmM2RhYWQ2YTJkYzdmM2EwOGE1NWMyYjg2MGRhNzIzNGRiN2U0ZDVmYjY1OWMwZTU5ODMwOWVjMzI4Mzk3NzNkMzgwYjEyN2IyMmZiYmVkODdhYjU2OGU0OWZmNDAxNWVlMWUsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpRME1Ea3hOREE1TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==');
@Component({
selector: "app-root",
template: `<div #spreadsheet></div>`
})
exportclassAppComponent {
@ViewChild("spreadsheet") spreadsheet: ElementRef;
// Worksheetsworksheets: jspreadsheet.worksheetInstance[];
// Create a new data gridngAfterViewInit() {
// Create spreadsheetthis.worksheets = jspreadsheet(this.spreadsheet.nativeElement, {
worksheets: [
{
minDimensions: [8,4],
style: {
'C:C': 'background-color: #ccffff; font-weight: bold',
'E1': 'background-color: #ccffff;',
},
}
]
});
}
}
Spreadsheet level style
Utilize the new spreadsheet-level style property in Jspreadsheet to easily apply and reuse CSS styles across multiple worksheets.
Sheet2
Search:
A
B
C
D
E
F
G
H
1
2
3
4
<html><scriptsrc="https://jspreadsheet.com/v10/jspreadsheet.js"></script><scriptsrc="https://jsuites.net/v5/jsuites.js"></script><linkrel="stylesheet"href="https://jspreadsheet.com/v10/jspreadsheet.css"type="text/css" /><linkrel="stylesheet"href="https://jsuites.net/v5/jsuites.css"type="text/css" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Material+Icons" /><divid="spreadsheet"></div><script>// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('Y2JjY2E5Yjk5Y2EyMzIxMDE4NGFkZmRhZmE5ZDdmM2RhYWQ2YTJkYzdmM2EwOGE1NWMyYjg2MGRhNzIzNGRiN2U0ZDVmYjY1OWMwZTU5ODMwOWVjMzI4Mzk3NzNkMzgwYjEyN2IyMmZiYmVkODdhYjU2OGU0OWZmNDAxNWVlMWUsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpRME1Ea3hOREE1TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==');
// Create the spreadsheetjspreadsheet(document.getElementById('spreadsheet'), {
worksheets: [{
minDimensions: [8,4],
style: {
'C:C': 0, // first position of the global array'E1': 1,
},
}],
style: [
'background-color: #ccffff; font-weight: bold',
'background-color: #ccffff'
],
});
</script></html>
importReact, { useRef } from"react";
import { Spreadsheet, Worksheet } from"@jspreadsheet/react";
const license = 'Y2JjY2E5Yjk5Y2EyMzIxMDE4NGFkZmRhZmE5ZDdmM2RhYWQ2YTJkYzdmM2EwOGE1NWMyYjg2MGRhNzIzNGRiN2U0ZDVmYjY1OWMwZTU5ODMwOWVjMzI4Mzk3NzNkMzgwYjEyN2IyMmZiYmVkODdhYjU2OGU0OWZmNDAxNWVlMWUsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpRME1Ea3hOREE1TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==';
exportdefaultfunctionApp() {
// Spreadsheet array of worksheetsconst spreadsheet = useRef();
// Styleconst globalStyle = [
'background-color: #ccffff; font-weight: bold',
'background-color: #ccffff'
]
const style = {
'C:C': 0, // first position of the global array'E1': 1,
}
// Render componentreturn (
<Spreadsheetref={spreadsheet}license={license}style={globalStyle}><Worksheetstyle={style}minDimensions={[8,4]} /></Spreadsheet>
);
}
Now JSS has the spreadsheet.style array of strings is used to declare the style strings, and the worksheet style property is used to assign those styles to the cells.
setStyle
The setStyle method adds style properties on top of the existing ones, but you can also use the fourth argument, forceOverwrite, to replace a current style with a new one.
Initialize style to range of cells
Specifying a new worksheet style using an Excel-like range of cell notation is possible.