Delete multiple rows not working as expected

Posted by: samuelstein on 8 September 2017, 1:11 am EST

  • Posted 8 September 2017, 1:11 am EST

    hello,

    i’m testing at the moment the [js]deleteRows()[/js] method. When i delete one row ([js]deleteRows(2, 1)[/js]) or multiple ([js]deleteRows(2, 10)[/js]) it is working as expected but when i try the following the bahavior is strange:

    [js]for (var i = 0; i < 10; i++) {

    getActiveSheet().deleteRows(2 + i, 1);

    }[/js]

    Is there a other way to achieve this because i have multiple ranges on my sheet which i want to delete.

    thanks in advance.

  • Posted 8 September 2017, 1:11 am EST

    Hello,

    I did not observe that behavior with the following code:

    [html]

        window.onload = function () {
            var spread = new GC.Spread.Sheets.Workbook(document.getElementById("spreadSheet"), { sheetCount: 1 });
            var activeSheet = spread.getActiveSheet();
    
            for (var r = 0; r &lt; 20; r++) {
                activeSheet.setText(r, 0, &quot;test&quot;+r);
                activeSheet.setValue(r, 1, r * 10);
            }
    
            for (var i = 0; i &lt; 10; i++) {
                activeSheet.deleteRows(2 + i, 1);
            }
        }
    

    [/html]

    The code successfully deletes every other row in the sheet. If the code isn’t working for you, then please create a small sample page that shows the issue so that I can investigate it further.

    Regards,

    Kevin

  • Posted 15 November 2017, 9:59 pm EST

    this code is working but if you change it slightly it won’t work anymore in version 10.2:

    window.onload = function () {
                var spread = new GC.Spread.Sheets.Workbook(document.getElementById("spreadSheet"), { sheetCount: 1 });
                var activeSheet = spread.getActiveSheet();
    
                for (var r = 0; r < 20; r++) {
                    activeSheet.setText(r, 0, "test"+r);
                    activeSheet.setValue(r, 1, r * 10);
                }
    
                for (var i = 0; i < [b]20[/b]; i++) {
                    activeSheet.deleteRows([b]i[/b], 1);
                }
            }
    
  • Posted 11 December 2017, 1:41 am EST

    Hello,

    In the above code , the for loop will delete the rows as per new index of row after each row is deleted. This will result in incorrect output.

    You should use the code below to delete rows:

    
      activeSheet.deleteRows(0, 20);
    
    

    Thanks,

    Deepak Sharma

  • Posted 14 February 2018, 8:58 pm EST

    thanks for the info. but my program requires to delete new added rows across the sheet. is it not possible to stop spread painting, then remove the cells and then activate painting again? or will the new index be created anyway?

Need extra support?

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

Learn More

Forum Channels