How to make spreadsheet Readonly without using Protected/Lock method

Posted by: timzod on 21 May 2018, 2:36 pm EST

    • Post Options:
    • Link

    Posted 21 May 2018, 2:36 pm EST

    Hello,

    I know that its not reasonable, currently i can use sheet.option.isProtected= true and cell.locked(true) to make spread sheet readonly.

    Now I have a sheet for template usage,its is protected already and the first row are designed as locked and other cells are all unlocked.

    I tried to use cell.locked(true) to make sheet readonly, but lead to OOM problem.

    So, anyone can tell me how to make a template sheet readlonly without modify the properties of all unlocked cells?

    Thanks very much!

  • Posted 22 May 2018, 5:21 pm EST

    Hello,

    You can cancel the editstarting event for Spread.Sheets to make it look like locked cells:

    var activeSheet = spread.getActiveSheet();

            activeSheet.bind(GC.Spread.Sheets.Events.EditStarting, function (sender, args) {
                e.preventDefault();
            });
    

    Thanks,

    Deepak Sharma

  • Posted 22 May 2018, 7:08 pm EST

    Thanks a lot, it works.

  • Posted 30 October 2018, 9:13 pm EST

    What is “e” in e.preventDefault() ?

  • Posted 30 October 2018, 9:55 pm EST

    I think

    args.cancel = true;

    This will stop the event.

  • Posted 31 October 2018, 5:14 pm EST

    Hello,

    Thank you for bringing it up; here is the correct code to lock the cell for edit in code:

    
      $(document).ready(function(){
        
                var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 2 });
                var sheet = spread.getActiveSheet();
                sheet.bind(GC.Spread.Sheets.Events.EditStarting, function (sender, args, e) {
                    if (args.col == 2)
                        {
                    e.preventDefault();
                    }
                    });
            });
    
    
    

    Thanks,

    Deepak Sharma

  • Posted 12 June 2019, 11:17 pm EST

    Can you recheck this? e is undefined. Event is not sent in the method.

  • Posted 13 June 2019, 8:55 pm EST

    Hi Pavan,

    Sorry for the confusion, You could cancel the edit event by setting cancel property to true on the args object. Please refer to the following code snippet:

    var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
    var sheet = spread.getActiveSheet();
    sheet.bind(GC.Spread.Sheets.Events.EditStarting, function(s, args){
        args.cancel = true;
    });
    
  • Posted 11 May 2020, 4:47 pm EST

    By using the above code I am able to paste data in cells. Is there any other way to prevent pasting data into cells?

  • Posted 12 May 2020, 12:05 am EST

    Hi

    To prevent pasting you may use ClipboardPasting Event. Please refer to the following code snippet and attached sample which demonstrates the same:

    spread.bind(GC.Spread.Sheets.Events.ClipboardPasting, (e, args) => {
        args.cancel = true;
      });
    

    sample: https://codesandbox.io/s/magical-liskov-1nwjw

    For more information please refer to the following API References:

    https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Sheets.Events~ClipboardPasting_EV.html

    Regards

  • Posted 13 July 2020, 10:30 pm EST

    1. how to cancel the event for DragFillBlockCompleted
    2. how to handle delete key via keyboard and cancel it?
  • Posted 15 July 2020, 12:44 am EST

    Hi,

    1. You may use DragFillBlock event and cancel it. Please refer to the following code snippet.
    spread.bind(GC.Spread.Sheets.Events.DragFillBlock, function(e, info) {
        info.cancel = true;
      });
    
    1. For this you may disable the delete key from the keyboard.Please refer to the following code snippet
    var commandManager = spread.commandManager();
      //46 is the keycode for Delete key
      commandManager.setShortcutKey(null, 46);
    

    API references:

    DragFillBlock:https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Sheets.Events~DragFillBlock_EV.html

    setShortcutKey:https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Commands.CommandManager~setShortcutKey.html

    Regards

  • Posted 4 August 2020, 8:30 pm EST

    Is there any other way to prevent setting RichText and Hyperlink into some specific cells?

  • Posted 5 August 2020, 8:41 pm EST

    Hi Vinayak,

    By default, SJS does not offer an option to input rich text, if we need the user to be able to input richText then we need to explicitly provide option for richtext, to disable it for some cells you just need to modify your code to not provide richtext option.

    For hyperlinks, you may set the allowAutoCreateHyperlink option to false:

    spread.options.allowAutoCreateHyperlink = false;
    

    More about hyperlinks: https://www.grapecity.com/spreadjs/docs/v13/online/hyperlink_cells.html

    Regards

Need extra support?

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

Learn More

Forum Channels