Merged cell range

Hello, after browsing through the documentation and forum, I am unable to find an example of getting the range of a merged cell area.


My goal is to parse a .xlsx file into JSON, and I need to somehow grab the range and place that data in to JSON object.

Would it be best to check for “isMergedArea” or something while I iterate over the cells, or is there a more optimized way to obtain all “MergedArea” before hand?

Hi,


Thanks for your posting and using Aspose.Cells.

Please see the following sample code. It should fit your needs. Let us know your feedback.

I have also attached the source excel file used in this code and shown the console output of the code for your reference. I have tested the code with the latest version: Aspose.Cells for Java v16.10.6.

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

Worksheet ws = wb.getWorksheets().get(0);

ArrayList lst = ws.getCells().getMergedCells();

for(int i=0; i<lst.size(); i++)
{
CellArea ca = (CellArea)lst.get(i);

System.out.println(ca);
}


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

Worksheet ws = wb.Worksheets[0];

ArrayList lst = ws.Cells.MergedCells;

for(int i=0; i<lst.Count; i++)
{
CellArea ca = (CellArea)lst[i];

Console.WriteLine(ca);
}

Console Output
Aspose.Cells.CellArea(C4:F9)[3,2,8,5]
Aspose.Cells.CellArea(J8:M18)[7,9,17,12]
Aspose.Cells.CellArea(C20:D27)[19,2,26,3]