Is there a way to define a global worksheet theme that automatically applies to

Posted by: averma on 28 July 2026, 1:06 pm EST

  • Posted 28 July 2026, 1:06 pm EST

    Is there a way to define a global worksheet theme or default worksheet configuration at the workbook level so that every newly created sheet automatically inherits these customisations?

    If not, is there a recommended API or pattern for applying worksheet-level styling to new sheets without having to manually reapply the same configuration each time?

    Are there any workbook-level defaults for properties such as:

    1. Gridline colours
    2. Row/column header styles
    3. Default cell styles
    4. Selection colours
    5. **Selection colours of corresponding headers **

      Other worksheet UI customisations

      If the recommended approach is to iterate through all sheets and apply the theme, is that considered the best practice from a performance perspective, especially for workbooks containing a large number of sheets?

    We’re using SpreadJS v18.2.3.

  • Posted 29 July 2026, 7:28 am EST

    Hi,

    Thanks for the detailed questions — I’ll go through each one.

    Is there a global/workbook-level theme that new sheets automatically inherit?

    No. In SpreadJS, theming and styling properties (currentTheme, gridline color, selection colors, header styles, default cell style) all live on the Worksheet object, not the Workbook. There isn’t a workbook-level setting that automatically cascades into sheets created after it’s set.

    Recommended pattern to avoid manually reapplying the same configuration

    The approach we recommend is to centralize your styling in one function, then trigger it automatically from the SheetChanged event at the workbook level. This event fires for every sheet insertion — whether the sheet is added through your code or by the end user clicking the “+” tab — so once it’s wired up, you never have to call it manually again:

    function applyWorkbookTheme(sheet) {
    sheet.currentTheme('YourCustomTheme');
    sheet.options.gridline = { color: '#c0c0c0', showHorizontalGridline: true, showVerticalGridline: true };
    sheet.options.selectionBackColor = '#d6e4ff';
    sheet.options.selectionBorderColor = '#4472c4';
    const cellDefault = new GC.Spread.Sheets.Style();
    cellDefault.font = '10pt Segoe UI';
    sheet.setDefaultStyle(cellDefault, GC.Spread.Sheets.SheetArea.viewport);
    const headerDefault = new GC.Spread.Sheets.Style();
    headerDefault.backColor = '#2f4f6f';
    headerDefault.foreColor = '#ffffff';
    sheet.setDefaultStyle(headerDefault, GC.Spread.Sheets.SheetArea.colHeader);
    sheet.setDefaultStyle(headerDefault, GC.Spread.Sheets.SheetArea.rowHeader);
    }
    // Bind once, at the workbook level
    spread.bind(GC.Spread.Sheets.Events.SheetChanged, function (sender, args) {
    if (args.propertyName === 'insertSheet') {
    applyWorkbookTheme(spread.getSheet(args.sheetIndex));
    }
    });

    Workbook-level defaults for the specific properties you asked about

    Gridline color: sheet.options.gridline — per-sheet only

    Row/column header style: sheet.setDefaultStyle(style, SheetArea.colHeader / rowHeader), or options.colHeaderBackColor / rowHeaderBackColor — per-sheet only

    Default cell style: sheet.setDefaultStyle(style, SheetArea.viewport) — per-sheet only

    Selection background/border color: sheet.options.selectionBackColor / selectionBorderColor — per-sheet only

    Selection color of corresponding headers: this one is actually not a per-sheet JS property at all — it’s controlled by CSS classes on the page (.gc-columnHeader-selected / .gc-rowHeader-selected for a fully selected column/row, .gc-columnHeader-highlight / .gc-rowHeader-highlight when some cells in that column/row are selected, plus the -hover and -normal variants). Because these are just stylesheet rules, they apply globally across every sheet and every workbook on the page automatically — no per-sheet code needed.

    Everything else (frozen line color, header auto-text, etc.): sheet.options.* — per-sheet only

    Is iterating through all sheets the best-practice approach performance-wise?

    For sheets that already exist (on load, or when bulk-creating many sheets), yes — there’s no bulk/global setter, so iterating is necessary. It performs well as long as you:

    Wrap the entire loop in spread.suspendPaint() / spread.resumePaint(), calling each once outside the loop rather than per sheet

    Use setDefaultStyle/options assignment rather than looping over individual cells — cost scales with the number of sheets, not the number of cells, so this stays fast even with a large sheet count

    Reuse a single Style/Theme instance rather than constructing a new one inside the loop

    spread.suspendPaint();
    spread.suspendEvent();
    try {
    for (let i = 0; i < spread.getSheetCount(); i++) {
    applyWorkbookTheme(spread.getSheet(i));
    }
    } finally {
    spread.resumeEvent();
    spread.resumePaint();
    }

    Best regards,

    Priyam

  • Posted 29 July 2026, 12:38 pm EST

    Thank you for your reply.

    Following on to your answer, We have implemented runtime light/dark theme switching by applying custom styles to the workbook and worksheets.

    We observed the following behaviour:

    Steps to Reproduce

    Open a workbook in Light theme.

    In the first worksheet, insert one or more rows or columns.

    Switch the application theme to Dark.

    Observe the inserted rows/columns.

    Actual Result

    All existing cells correctly update to the Dark theme.

    However, the newly inserted rows/columns remain in the previous (Light) theme instead of adopting the new Dark theme.

    The opposite scenario also occurs:

    Start in Dark mode.

    Insert rows/columns.

    Switch to Light mode.

    The inserted rows/columns continue using the Dark theme.

    Expected Result

    When the application theme changes, all cells, including any rows or columns inserted after initial workbook creation, should adopt the currently applied theme consistently.

    Additional Question

    Besides row/column insertion, we suspect there may be other operations that create new cells or regions which do not automatically inherit the updated workbook theme (for example, inserting sheets, copy/paste operations, expanding tables, etc.).

    Is there a recommended approach or API that ensures all newly created content automatically inherits the active theme, regardless of how it is created, without having to manually handle every possible operation?

    If this is expected behaviour, could you please advise on the best practice for keeping workbook styling consistent across all runtime modifications?

  • Posted 30 July 2026, 6:39 am EST - Updated 30 July 2026, 6:44 am EST

    Hi Ashish,

    Thank you for the follow-up and for outlining the reproduction steps.

    We attempted to reproduce the behavior using a simplified sample that follows the workflow you described (switching between Light and Dark themes after inserting new rows/columns). However, we were unable to observe the reported behavior. In our testing, both the existing cells and the newly inserted rows/columns correctly adopted the updated theme after switching.

    You can refer to the sample - CustomTheme, which demonstrates the perfect working of the theme switching.

    In case the issue does not resolve on your end, please share a stripped-down sample application with us replicating the issue. You can also fork, modify, and share the above sample.

    Looking forward to your input.

    Kind Regards,

    Chirag

    Working:

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels