Posted 14 January 2025, 7:24 am EST
Hi,
In SpreadJS, styles are applied at the worksheet level rather than the workbook level. This behavior aligns with Excel’s functionality, where applying styles to the current sheet does not impact other sheets in the workbook.
To apply default styles across all worksheets, you will need to iterate through each sheet in the workbook. Below is an example implementation for your reference:
Code Snippet
// Ensuring the default style is applied to the active sheet
spread.bind(GC.Spread.Sheets.Events.ActiveSheetChanged, function (e, args) {
if (isStyleApplied) {
var sheet = args.newSheet;
sheet.setDefaultStyle(defaultStyle , GC.Spread.Sheets.SheetArea.viewport);
}
});
// Adding styles to all worksheets in the workbook
document.getElementById('addStyle').addEventListener("click", function () {
var sheetCount = spread.getSheetCount();
isStyleApplied = true;
for (var i = 0; i < sheetCount; i++) {
var sheet = spread.getSheet(i);
sheet.setDefaultStyle(defaultStyle , GC.Spread.Sheets.SheetArea.viewport);
}
});
For newly created worksheets, you can use the ActiveSheetChanged event to apply the default style to the new sheets.
Sample: Sample.zip
You could refer to the attached sample project that demonstrates this functionality in detail.
References :-
ActiveSheetChanged: https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.Events#activesheetchanged
setDefaultStyle API = https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.Worksheet#setdefaultstyle
If you have further questions or require additional assistance, feel free to reach out.
Best regards,