This article provides examples of unmerging an individual merged cell or an Area that may contain one or more merged cells.
Unmerging a single cell
C# Example:
Cell cell = wb.Worksheets[0].Cells[0,0];
if(cell.IsMerged)
cell.Unmerge();
Unmerging an Area of cells
Although the Merge method is on the Area object, the Unmerge method is only on the Cell object. This is because each cell knows whether it is part of a merged cell, but a given area can be defined to include both merged and unmerged cells.
There are two ways to unmerge an area of cells:
- If you know exactly where the merged cells are, you can unmerge any one cell and the entire merged area will be unmerged.
- Or, loop through all the cells in an area to find merged cells and unmerge them.
C# Example:
Area a = wb.Worksheets[0].CreateArea("A1:C4");
for(int i=0;i<a.RowCount-1;i++)
{
for(int j=0;j<a.ColumnCount-1;j++)
{
Cell cell = wb.Worksheets[0].Cells[i,j];
if(cell.IsMerged)
cell.Unmerge();
}
}
|