Problems getting activeSheet tabs visible with large workbook

Posted by: georgeg on 14 August 2025, 2:02 pm EST

    • Post Options:
    • Link

    Posted 14 August 2025, 2:02 pm EST - Updated 14 August 2025, 3:56 pm EST

    Hi had some problems when making an activeSheet’s tab visible via a button control. Ideally the control I tried should scroll to the tab that is the active sheet. Problem is we could have 20 sheets of workbook with really large names so its not like I have 3 short named tabs visible all the time.

    The following code does NOT work (note: CoPilot acts like getTabStrip is an accessible function: it is not):

    //(1):
    // I know now getTabStrip is either non-accessible or nonexistent 
    function changeActiveSheet(sheetName) {
        const designer = GC.Spread.Sheets.Designer.findControl(document.getElementById('spreadJsSpreadsheet'));
        const spread = designer.getWorkbook();
    
        spread.setActiveSheet(sheetName);
        spread.getTabStrip().scrollToSheet(sheetName);// Not attached to workbook; getTabStrip is either non-accessible or a nonexistent function?
    
    }
    
        tryScrollToTab();
    }
    
    //(2):
    function changeActiveSheet(sheetName) {
        const designer = GC.Spread.Sheets.Designer.findControl(document.getElementById('spreadJsSpreadsheet'));
        const spread = designer.getWorkbook();
    
        spread.setActiveSheet(sheetName);
    
        let attempts = 0;
        const maxAttempts = 10;
        const delay = 300; // ms between retries
    
        function tryScrollToTab() {
            if (spread.getTabStrip && typeof spread.getTabStrip === "function") {
                spread.getTabStrip().scrollToSheet(sheetName); //Again doesn't work;  getTabStrip is either non-accessible or nonexistent.
            } else if (attempts < maxAttempts) {
                attempts++;
                setTimeout(tryScrollToTab, delay);
            } else {
                console.warn("Tab strip still not available after multiple attempts.");
            }
        }
    
        tryScrollToTab();
    }
    
    //(3):
    function changeActiveSheet(sheetName) {
        const designer = GC.Spread.Sheets.Designer.findControl(document.getElementById('spreadJsSpreadsheet'));
        const spread = designer.getWorkbook();
    
        spread.setActiveSheet(sheetName);
    
        setTimeout(() => {
            const activeSheet = spread.getActiveSheet();
            if (activeSheet) {
                spread.setActiveSheet(activeSheet.name()); // Re-setting may trigger tab visibility? Nope.
            }
        }, 1000);
    
    }

    the getTabStrip() function seems like it doesn’t exist or isnt recongnized as part of the workbook. I get errors or warnings like: “1587 EXECPTION THROWN : spread.getTabStrip is not a function”

    When I load the workbook some raw data from an HTTP request response (JSON) It seems to work fine:

            var designer = GC.Spread.Sheets.Designer.findControl(document.getElementById('spreadJsSpreadsheet'));
            var spread = designer.getWorkbook();
    
    //Later after loading the workbook:
            //Organize the workbook: set the active sheet name, put in proper order and make active sheet's tab visible.
    
            let newActiveSheetName = scrubSheetName(data[0].reportName);       //Grab the name of the new active sheet.
            
            let desiredOrder = getDesiredOrderFromTreeList("reportsTreeList"); //get the order of the sheets, dicatated by the Reports Treelist order.
    
            desiredOrder.forEach((sheetName, index) => {                       //Order the sheets.
                spread.changeSheetPosition(sheetName, index);
            });
    
            spread.setActiveSheet(newActiveSheetName);                        //Set the active sheet.
    
           // spread.getTabStrip().scrollToSheet(newActiveSheetName);           // Ensures the active sheet's tab is visible. I know now getTabStrip is either nonaccessible or nonexistent  :(

    Any ideas?

    George

  • Posted 18 August 2025, 5:23 am EST - Updated 18 August 2025, 5:28 am EST

    Hi George,

    You are correct - getTabStrip() is not part of the SpreadJS API. To ensure the active sheet’s tab is visible, you can use the startSheetIndex method on the workbook as follows:

    const activeSheet = spread.getActiveSheet();
    spread.startSheetIndex(spread.getActiveSheetIndex());

    This will scroll the activesheet to the tabstrip visible port. You can also refer to the attached sample that uses the above code snippet and brings the active sheet to the visible tabstrip (see below).

    Please feel free to reach out if you encounter any further issues or require additional assistance.

    Attachment: https://jscodemine.mescius.io/share/u8_hIlUW30KWkwem6Gi1rA/?defaultOpen={"OpenedFileName"%3A["%2Findex.html"%2C"%2Fapp.js"]%2C"ActiveFile"%3A"%2Fapp.js"}

    References:

    1. getActiveSheetIndex - https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.Workbook#getactivesheetindex
    2. startSheetIndex - https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.Workbook#startsheetindex

    Working:

    Kind Regards,

    Chirag Gupta

  • Posted 21 August 2025, 2:32 pm EST

    Ok… works great… sorry I was down another rabbit hole and over thought this problem. :slight_smile:

    George

Need extra support?

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

Learn More

Forum Channels