Merge Cell very slow

Hi all,
I’m using Aspose.Cells 19.2 and using Cell.Merge(),
I have more than 300.000 cell need merge, but while running program is slow down.
Can you help me make it faster?

Thank and best regard!

@DungLT,
Please share your sample file and code snippet with us for our testing. We will reproduce the problem and provide our feedback after analysis.

When I disable merging, each 1000 rows take ~0.15s (~30s to complete)
NoMerge.PNG (3.0 KB)

But if enable merging, each rows take ~2s ( ~200000 row merged) (~250s to complete)
Merged.PNG (4.9 KB)

here is my standalone project
WindowsFormsApp2.zip (5.2 MB)

@DungLT,
It seems that some different code is shared as it cannot be compiled. Please share running project (compilable without errors) for our testing. We will analyze the code and share our feedback.
CodeBugs.PNG (28.3 KB)

Oh sorry,
My project using Component One and here is my DLL
C1_Flexgrid.zip (569.8 KB)

Please feedback me soon. Thank you.

@DungLT,
Please use this method, which will ignore checking Conflicted merged cells and work faster.

Cells.Merge(int firstRow, int firstColumn, int totalRows, int totalColumns, false,false)

Let us know your feedback.

I used it but it does’t work.
Time delay still increase :frowning:
Capture.PNG (4.2 KB)

@DungLT,
We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-46724 - Slow cell merge
1 Like

Thanks for your support.
I hope you check and notify for me soon. :slight_smile:

@DungLT,
You are welcome and sure we will let you know immediately once any feedback is ready.

@DungLT,

Please merge cells before setting the data, it should figure out your issue. See the following sample code for your reference:
e.g
Sample code:

......
for (int _nRow = 0; _nRow < Numrow; _nRow++) {
_worksheet.Cells.Merge(_nRow, 10, 1, 3, false, true);
}
for (int _nRow = 0; _nRow < Numrow; _nRow++) {
var _row = grid.Rows[_nRow]; 
......

Let us know if you still find the issue.

@Amjad_Sahi
I can’t merge cells before setting data for some reasons :frowning:

@DungLT,

Please check the following sample code for your reference. If you enable merging with _worksheet.Cells.Merge(_nRow, 10, 1, 3, false,false); the code takes about 82s. If you disable merging, the codes takes about 87s. So, it works fine with checkConflict as false.

Please share your finding after trying the following codes:
e.g
Sample code:

using (var _workbook = new Workbook()) {
_workbook.Settings.MemorySetting = MemorySetting.MemoryPreference;
var _worksheet = _workbook.Worksheets[0];
_worksheet.IsGridlinesVisible = false;
var _cellFactory = new CellsFactory();

var _st = new Stopwatch();                var _st2 = new Stopwatch();
_st2.Start();
for (int _nRow = 0; _nRow < 200000; _nRow++)
{
for (int _nCol = 0; _nCol < 30; _nCol++)
 {                        var _xlCell = _worksheet.Cells[_nRow, _nCol];                        var _xlStyle = _xlCell.GetStyle();
if (_xlStyle == null)                            _xlStyle = _cellFactory.CreateStyle();
_xlStyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;                        _xlStyle.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;                        _xlStyle.Borders[BorderType.BottomBorder].Color = Color.LightGray;                        _xlStyle.Borders[BorderType.RightBorder].Color = Color.LightGray;
_xlStyle.Font.Size = 9;
_xlStyle.Pattern = BackgroundType.Solid;                        _xlStyle.ForegroundColor = Color.Red;
_xlCell.SetStyle(_xlStyle);
_xlCell.Value = _nRow ":" _nCol;
}
// _worksheet.Cells.Merge(_nRow, 10, 1, 3, false,false);
if (_nRow % 1000 == 0)
{                        _st.Stop();                        Trace.WriteLine($"{_st.Elapsed.TotalSeconds}s, {_nRow} rows");                        _st.Restart();                    }                }
_st2.Stop();
Console.WriteLine($"Saved in : {_st2.Elapsed.TotalSeconds} seconds");
_workbook.Save(dir +"dest.xlsx", SaveFormat.Xlsx);