We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Detecting merged cells and row/column count

Hello, for a .NET project we need to detect if a particular cell is a merged one, and in that case get the number of rows/columns that the merged cell contains. Could you please help us with some sample code to reach that??


Thanks

Hi,

Thanks for your posting and using Aspose.Cells.

You can use the following properties and method for your needs.

  • Cells.MergedCells
  • Cell.IsMerged
  • Cell.GetMergedRange()

Please see the following sample code which illustrates how to make use of the above properties. I have attached the sample excel file used in this code and console output generated by the code for your reference.

C#


Workbook wb = new Workbook(“sample.xlsx”);


Worksheet ws = wb.Worksheets[0];


ArrayList mcells = ws.Cells.MergedCells;


//Print merged cells area

for (int i = 0; i < mcells.Count; i++)

{

CellArea area = (CellArea)mcells[i];


Console.WriteLine(area);


}


//Check if some particular cell is merged

Cell cell = ws.Cells[“F6”];

Console.WriteLine(cell.IsMerged);

Console.WriteLine(cell.GetMergedRange());

Console Output:
Aspose.Cells.CellArea(D5:H7)[4,3,6,7]
Aspose.Cells.CellArea(B11:G13)[10,1,12,6]
True
Aspose.Cells.Range [ Sheet1!D5:H7 ]