Home     Products      Support      Corporate     Sign In 

Support Knowledge Base, Article 1237

Product
ExcelWriter
Title
Unmerging cells in version 6.8.1 and above
Problem
The .NET version of ExcelWriter has always had the ability to merge cells, however prior to version 6.8.1, there was no way to unmerge cells in an existing spreadsheet. This functionality has been added with the new Unmerge method of the Cell object. We have also added a convenient IsMerged property to determine whether or not a given cell is merged.
Solution
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:

  1. If you know exactly where the merged cells are, you can unmerge any one cell and the entire merged area will be unmerged.
  2. 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();
       }
  }
Created : 4/23/2007 12:19:31 PM (last modified : 4/23/2007 12:19:31 PM)

Rate this article!

 
Comments



Copyright 2006 © SoftArtisans, Inc. All Rights Reserved.

Site Map     |     Privacy Policy     |     Contact Us