Merged cell

Hi Laurence

Is there any way of, given a cell, determining whether is merged or not? Thanks.


Steve

Currently you cannot know if a cell is a merged one. Could you tell me why you need this feature?

Hi Laurence,

I guess this isn’t really a critical issue… I was just trying to overcome the problems with using autofitcolumn on merged cells. Basically, I’m going through each cell’s content, determining the length and setting the column width. Merged cells needed to be handled differently from regular cells so that’s why I need to check if a cell is part of a merged range or not.

Steve

Hi Steve,

I will add a new property Cell.IsMerged to let you know if a cell is part of a merged range or not.

Please download v2.7.5 and try

and use Cell.IsMerged property.

@Steve,
Aspose.Cells has replaced Aspose.Excel that is no more under active development and is discontinued. Aspose.Cells is much advanced as compared to its predecessor and other spreadsheet processing products. It not only supports all the features of its predecessor but also supports advanced features available in different versions of MS Excel.You can detect merged cells using this product as well as demonstrated in the following sample code:

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

// Instantiate a new Workbook
// Open an existing excel file
Workbook wkBook = new Workbook(dataDir+ "SampleInput.xlsx");
// Get a worksheet in the workbook
Worksheet wkSheet = wkBook.Worksheets["Sheet2"];
// Clear its contents
wkSheet.Cells.Clear();

// Create an arraylist object
ArrayList al = new ArrayList();
// Get the merged cells list to put it into the arraylist object
al = wkSheet.Cells.MergedCells;
// Define cellarea
CellArea ca;
// Define some variables
int frow, fcol, erow, ecol, trows, tcols;
// Loop through the arraylist and get each cellarea
// To unmerge it
for (int i = 0; i < al.Count; i++)
{
    ca = new CellArea();
    ca = (CellArea)al[i];
    frow = ca.StartRow;
    fcol = ca.StartColumn;
    erow = ca.EndRow;
    ecol = ca.EndColumn;

    trows = erow - frow + 1;
    tcols = ecol - fcol + 1;
    wkSheet.Cells.UnMerge(frow, fcol, trows, tcols);
}
dataDir = dataDir+ "MergeTrial.out.xlsx";
// Save the excel file
wkBook.Save(dataDir);

Here are the articles that can be referred to for the merging of cells:
Detect Merged Cells in a Worksheet
Merging and Unmerging Cells
Merge or Unmerge Range of Cells

A free trial version is available here for testing the product features:
Aspose.Cells for .NET (Latest Version)

Here is a runnable solution to test the product features with the help of hundreds of ready to run examples.