Protect Cell

I'm trying to make a cell read-only.  I want other parts of the document editable.  Can you describe the steps?  I can't seem to get it to work with protect sheet and then, perhaps setting isLocked?  

Perhaps the technique should be to handle the edit/format/etc. events and reject changes?  

Thanks!  


1 Reply

BP Babu Periyasamy Syncfusion Team July 11, 2024 01:51 PM UTC

Hi Jonathan Asbury,


We have checked your reported query of protecting the cells of Spreadsheet without protecting the whole sheet. And it can be achieved by using the setRangeReadOnly public method of our Spreadsheet component which was available from the 26.1.35 version.


Using the setRangeReadOnly method, you can make the range of cells, an entire row and column without protecting the whole spreadsheet. For your convenience, we have prepared the sample in which we have make the cells in the used range to read-only without protecting the worksheet in the created event. Below attached the prepared sample along with the code snippet and video demonstration for your reference,


Code snippet:


const onCreated = () => {

        spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center', verticalAlign: 'middle' }, 'A1:F1');

        let sheet = spreadsheet.getActiveSheet();

        //Construct the address based on the used range.

        let usedRangeAddress = getRangeAddress([0, 0, sheet.usedRange.rowIndex, sheet.usedRange.colIndex]);

        //Make the cells read-only in the used range using the setRangeReadOnly method.

        spreadsheet.setRangeReadOnly(true, usedRangeAddress, spreadsheet.activeSheetIndex);

    }


Sample link: https://stackblitz.com/edit/react-pg3c8l-dh61y7?file=index.js


Video link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Read_only_cells6764551


For more information regarding the setRangeReadOnly method, please refer the below documentation,

https://ej2.syncfusion.com/react/documentation/spreadsheet/protect-sheet#make-cells-read-only-without-protecting-worksheet


Kindly, check the above deatils and get back to us for further clarification.


Loader.
Up arrow icon