Detect Merged Cells using Aspose.Cells

Aspose.Cells - Detect Merged Cells

In Microsoft Excel, several cells can be merged into one. This is often used to create complex tables or to create a cell that holds a heading that spans several columns.
Aspose.Cells allows you to identify merged cell areas in a worksheet. You can unmerge them too.

Java

 // Get the merged cells list to put it into the **ArrayList** object
ArrayList<CellArea> al = worksheet.getCells().getMergedCells();

// Define a **CellArea**
CellArea ca;

// Define some variables
int frow, fcol, erow, ecol;

// Print message
System.out.println("Merged Areas: \n"+ al.toString());

// Loop through the **ArrayList** and get each **CellArea** to unmerge it
for(int i = al.size()-1 ; i > -1; i--)
{
    ca = new CellArea();
    ca = (CellArea)al.get(i);
    frow = ca.StartRow;
    fcol = ca.StartColumn;
    erow = ca.EndRow;
    ecol = ca.EndColumn;
    System.out.println((i+1) + ". [" + fcol +"," + frow +"] " + "[" + ecol +"," + erow +"]");
    worksheet.getCells().unMerge(frow, fcol, erow, ecol);
}

Download Running Code

Download Sample Code