NamedRange.MergeCells 属性
获取或设置一个值,该值指示 NamedRange 控件是否包含合并单元格。
命名空间: Microsoft.Office.Tools.Excel
程序集: Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)
语法
声明
Property MergeCells As Object
Get
Set
Object MergeCells { get; set; }
属性值
类型:System.Object
如果 NamedRange 控件包含合并单元格,则为 true;否则为 false。
示例
下面的代码示例在使用 Merge 方法合并包含单个单元格 NamedRange 的多单元格 NamedRange 之前和之后,显示单个单元格 NamedRange 的 MergeArea 和 MergeCells 属性的值。
此示例针对的是文档级自定义项。
Private Sub MergeRange()
Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
= Me.Controls.AddNamedRange(Me.Range("A1", "A5"), _
"namedRange1")
Dim namedRange2 As Microsoft.Office.Tools.Excel.NamedRange _
= Me.Controls.AddNamedRange(Me.Range("A1"), "namedRange2")
Dim beforeMergeAddress As String = _
namedRange2.MergeArea.Address(, , _
Excel.XlReferenceStyle.xlA1, , )
MessageBox.Show("Before merging, the MergeArea property is '" & _
beforeMergeAddress & "' and the MergeCells property is " & _
" '" & namedRange2.MergeCells.ToString() & "'.")
namedRange1.Select()
namedRange1.Merge(False)
Dim afterMergeAddress As String = _
namedRange2.MergeArea.Address(, , _
Excel.XlReferenceStyle.xlA1, , )
MessageBox.Show("After merging, the MergeArea property is '" & _
afterMergeAddress & "' and the MergeCells property is " & _
" '" & namedRange2.MergeCells.ToString() & "'.")
End Sub
private void MergeRange()
{
Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
this.Controls.AddNamedRange(this.Range["A1", "A5"],
"namedRange1");
Microsoft.Office.Tools.Excel.NamedRange namedRange2 =
this.Controls.AddNamedRange(this.Range["A1", missing],
"namedRange2");
string beforeMergeAddress = namedRange2.MergeArea.get_Address(
missing, missing, Excel.XlReferenceStyle.xlA1, missing, missing);
MessageBox.Show("Before merging, the MergeArea property is '" +
beforeMergeAddress + "' and the MergeCells property is " +
" '" + namedRange2.MergeCells.ToString() + "'.");
namedRange1.Select();
namedRange1.Merge(false);
string afterMergeAddress = namedRange2.MergeArea.get_Address(
missing, missing, Excel.XlReferenceStyle.xlA1, missing, missing);
MessageBox.Show("After merging, the MergeArea property is '" +
afterMergeAddress + "' and the MergeCells property is " +
" '" + namedRange2.MergeCells.ToString() + "'.");
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。