Merge operation works to slow

3 posts, 1 answers
  1. Ars
    Ars avatar
    7 posts
    Member since:
    Aug 2011

    Posted 22 Nov 2015 Link to this post

    Hi, 

    I`m playing with Excel export task using SpreadProcessing.

    I`ve notice that when i`m using merge for cellSelection - time needed to write to workbook increases dramatically. 

    I made simple test -  cycle with 10000 inserts operations and merges of two cells (horizontal merge).

    The results for cycle:

    - with merge takes 00:00:06.3593555

    - without merge takes 00:00:00.1815065

     My code:

    var workbook = CreateWorkbook();
     workbook.History.IsEnabled = false;
    workbook.SuspendLayoutUpdate();           
    var worksheet = workbook.ActiveWorksheet;          
    for (int i = 0; i < 10000; i++)
    {
        CellIndex cellIndex = new CellIndex(i, 0);
        worksheet.Cells[cellIndex].SetValue("Data " + i);
        worksheet.Cells[cellIndex].SetHorizontalAlignment(RadHorizontalAlignment.Left);
        worksheet.Cells[i, 0, i, 2].MergeAcross();
    }
    workbook.ResumeLayoutUpdate();
    workbook.History.IsEnabled = true;

    Although, I made test with merge from 0 to 8 column. Result - 00:00:15.4579052.

    Is there any workaround of such perfomance issue? 

     

  2. Answer
    Nikolay Demirev
    Admin
    Nikolay Demirev avatar
    103 posts

    Posted 23 Nov 2015 Link to this post

    Hi Ars,

    Merging of cells copies the formatting values from the top left cell of the merged area to the whole merged area. These properties are 19 cell properties. For merging one cell range, each property value is retrieved and then set to the entire range. That mean for the merging of 10000 ranges minimum 380000 read and write operations are performed on the internal structures.

    If you just set the cell values only 10000 write operations are performed on the internal structures. That is why merging of cells takes so long.

    We are currently working on a new library which is meant only for export scenarios. And it is extremely fast. It will be released with the Q1 2016 release.

    Regards,
    Nikolay Demirev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Ars
    Ars avatar
    7 posts
    Member since:
    Aug 2011

    Posted 24 Nov 2015 Link to this post

    Hi, Nikolay Demirev

     thank you for fast reply.

    I'll look forward to the Q1 2016 release. 

     For others, for now I create my report with EPPlus on the server sider of my app. It works very fast. 

Back to Top