Merged VSTO cells
The shortest way here is to use the Boolean property Range.MergeCells
.
Assuming your cell reference has been named myCell
, you can 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 can also check Cells.Count
in the range returned by the property Range.MergeArea
:
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 Range.Cells.Count by design.
source to share
Assuming you are using a method that can invoke and use the Excel Object Model, you check the cell's MergeArea property to see if it contains anything other than that cell. If so, then this cell is part of the MergeArea. This is how I did 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.
source to share