Skip to main content Skip to footer

How to set a worksheet limit of SpreadJS in pure JavaScript

Background:

 You are able to bind the SheetChanging event to the spread instance so that when a change happens you would than get the sheet count using the getSheetCount method

When the sheet count hits a specified number, set the Spread Controls Options newTabVisible to False, so now the special tab to let users insert new  sheets will no longer appear.

Steps to Complete:

1. Bind the SheetChanged event to the Spread Instance

2. Get the sheet count

3. Set NewTabVisible according to desired sheet limit

Getting Started:

Step 1: Bind the SheetChanged event to the Spread Instance

  // 1.) Bind the SheetChanged Event to the Spread instances
  spread.bind(GC.Spread.Sheets.Events.SheetChanged, function (sender, args) {
  
  });

Step 2: Get the sheet count

  // 1.) Bind the SheetChanged Event to the Spread instances
  spread.bind(GC.Spread.Sheets.Events.SheetChanged, function (sender, args) {
    // 2.) Get the sheet counnt
    var sheetCount = spread.getSheetCount();
    
  });

Step 3: Set newTabVisible according to desired sheet limit

For example, if your sheet limit is 3, set it so that if the sheet count is greater than or equal to 3 set the newTabVisible option to False. Otherwise, set the newTabVisible to True.

      // 1.) Bind the sheetChanged event to the Spread instances
      spread.bind(GC.Spread.Sheets.Events.SheetChanged, function (
        sender,
        args
      ) {
        // 2.) Get the sheet counnt
        var sheetCount = spread.getSheetCount();
        // 3.) Determining your sheet limit to set the newTabVisible option
        if (sheetCount >= 3) {
          spread.options.newTabVisible = false;
        } else {
          spread.options.newTabVisible = true;
        }
      });

Notice, after adding this your SpreadJS instance will not allow a user to add more than 3 sheets.

Mackenzie Albitz