Lock and hide last column

Posted by: l.ficara on 29 July 2024, 3:17 am EST

    • Post Options:
    • Link

    Posted 29 July 2024, 3:17 am EST

    Hi everyone,

    I’m trying to lock and hide the last column of my Excel, but it doesn’t work.

    Following my code:

    let secondArray = body.values[1];

    let lastCol = secondArray.length-1;

                matrixSheet.getRange(0, lastCol, row, 1).locked(true);
                matrixSheet.getRange(0, lastCol, row, 1).visible(false);
    
                matrixSheet.addRows(row, body.values.length);
    
                matrixSheet.setArray(2, 0, body.values);
    

    For values I’ve an array of array, so I’m going to lock and hide the last one column of every row.

    Is that correct?

    Regards,

    Lorenzo

  • Posted 30 July 2024, 2:46 am EST - Updated 30 July 2024, 2:51 am EST

    Hi,

    If you want to lock and make the last column visible, you need to select the whole column by using -1 for the row and rowCount arguments in the getRange function. Refer to the attached snippet and gif “SpreadJS.gif.”

    let activeSheet = spread.getActiveSheet();
    
    activeSheet.getRange(-1, 19, -1, 1).locked(true);
    activeSheet.getRange(-1, 19, -1, 1).visible(false);
    // Or
    // activeSheet.setColumnVisible(19, true);

    Instead of the visible method, you can also use the setColumnVisible API to hide and unhide the column.

    Gif:

    References:

    setColumnVisible:

    https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.Worksheet#setcolumnvisible

    Regards,

    Priyam

  • Posted 30 July 2024, 2:55 am EST

    Hi Priyam,

    Thank you so much, you saved my day!

  • Posted 31 July 2024, 12:42 am EST

    Hi,

    We are happy that your query has been resolved.

    You could always create new cases for new queries/issues.

    Regards,

Need extra support?

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

Learn More

Forum Channels