How to select a specific cell/range without mouse click

Posted by: ngocnguyen09910060 on 28 August 2022, 10:27 am EST

  • Posted 28 August 2022, 10:27 am EST

    Hi teams,

    End user copy a string from another application (such as: Notepad++).

    After that, end user access my application and they want to paste the above string to a specific cell on SpreadJS without select this cell by mouse click.

    So, after init spread, i want to set default specific cell/range and allow user to paste as the above requirement.

    How can i do it ?

  • Posted 29 August 2022, 6:56 am EST

    Hi,

    For this, you may override the clipboarPaste Command. Please refer to the following code snippet and let me know if you face any issues.

    
    let old = GC.Spread.Sheets.Commands.clipboardPaste.execute;
    GC.Spread.Sheets.Commands.clipboardPaste.execute = function (
      spread,
      options,
      isUndo
    ) {
      console.log(options);
      if (!options.fromSheet) {
        // user pasting from outside of spreadJS
        let sheet = spread.getSheetFromName(options.sheetName);
        sheet.setActiveCell(1, 1);
        options.pastedRanges = [new GC.Spread.Sheets.Range(1, 1, 1, 1)];
      }
      return old.apply(this, [spread, options, isUndo]);
    };
    
    

    Regards,

    Avinash

  • Posted 30 August 2022, 2:16 pm EST

    Hi avinash.pathak,

    Your solution is only working after user click on SpreadJS.

    My problem is:

    1. User access my application.
    2. User don’t click any position on SpreadJS.
    3. User press Ctrl + V.

    Please help me.

  • Posted 30 August 2022, 11:56 pm EST

    HI,

    For this, whenever the application load you need to set the focus on the spread. Please refer to the following code snippet since I am using pureJS so I used onload method but you are using any other framework you need to use the lifecycle method of the component.

    
    window.onload = function () {
    	// host the workbook control in a DIV element with id "ss"
    	var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), {
    		sheetCount: 1
    	});
    	[b]spread.focus(true);[/b]
    
    	/*
    	* retrieve the spread workbook object from the host element using findControl static method.
    	* var spread = GC.Spread.Sheets.findControl(document.getElementById('ss'));
    	*/
    	initSpread(spread);
    };
    
    
    

    regards,

    Avinash

Need extra support?

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

Learn More

Forum Channels