共用方式為


NamedRange.MergeArea 屬性

取得 Microsoft.Office.Interop.Excel.Range,表示 NamedRange 控制項包含合併的範圍。

命名空間:  Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)

語法

'宣告
ReadOnly Property MergeArea As Range
    Get
Range MergeArea { get; }

屬性值

型別:Microsoft.Office.Interop.Excel.Range
Microsoft.Office.Interop.Excel.Range ,表示 NamedRange 控制項包含合併的範圍。如果 NamedRange 控制項不在合併的範圍內,則這個屬性會傳回 Microsoft.Office.Interop.Excel.Range,表示 NamedRange 控制項。

備註

MergeArea 屬性只適用於單一儲存格範圍。

範例

在下列範例中,程式碼會顯示在使用 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 安全性

請參閱

參考

NamedRange 介面

Microsoft.Office.Tools.Excel 命名空間