Is there any way in VSTO (/JET OLEDB or other methods of reading excel files) to tell if the data comes from a single cell or merged range of cells and get this range ?
A:
Assuming the you use a method that can invoke & use the Excel object model, you check the MergeArea property of a cell to see if it contains anything other than that cell. If it does, then that cell is part of a MergeArea. Here's how I've done it in VBA:
IF CurrCell.MergeArea.Rows.Count > 1 Or CurrCell.MergeArea.Columns.Count > 1 Then
'CurrCell is part of a MergeArea... '
The equivalent C# VSTO code should be fairly similar.
RBarryYoung
2009-09-30 18:06:48
this is very interesting, I will check that solution and mark as answered if it does the job.
Jacob
2009-09-30 18:18:44
A:
The shortest route here is to make use of the Boolean Range.MergeCells
property.
Assuming that your cell reference were named myCell
, you could use something like:
if (myCell.MergeCells)
{
// The 'myCell' is part of a merged cell area.
}
Else
{
// The 'myCell' is not part of any merged cell area.
}
You could also check the Cells.Count
on the Range returned by the Range.MergeArea
property:
if (myCell.MergeArea.Cells.Count > 1) {...}
or:
if (myCell.MergeArea.Count > 1) {...}
The last example works because the Range.Count property always returns the same value as does the Range.Cells.Count, by design.
Mike Rosenblum
2009-09-30 20:53:34