获取 NamedRange 控件的范围引用。
命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)
语法
声明
ReadOnly Property Address As NamedRange_AddressType
    Get
NamedRange_AddressType Address { get; }
属性值
类型:Microsoft.Office.Tools.Excel.NamedRange_AddressType
一个字符串,表示 NamedRange 控件的用 R1C1 或 A1 样式表示法表示的范围引用。
备注
Address 属性旨在与下列参数一起使用。
| Parameter | 说明 | 
|---|---|
| RowAbsolute | 如果将行作为绝对引用返回,则为 true。 默认值为 true。 | 
| ColumnAbsolute | 如果将列作为绝对引用返回,则为 true。 默认值为 true。 | 
| ColumnAbsolute | XlReferenceStyle 值之一。 | 
| External | 如果返回外部引用,则为 true;如果返回本地引用,则为 false。 默认值为 false。 | 
| RelativeTo | 一个用于定义起始点的 Range。 如果 RowAbsolute 和 ColumnAbsolute 为 false,ReferenceStyle 为 xlR1C1,则必须包括相对引用的起始点。 | 
如果尝试在不指定任何参数的情况下使用 Address,则 Address 将获取一个 NamedRange_AddressType 对象,该对象是 Visual Studio 基础结构的一部分,不应在代码中直接使用。
如果该引用中包含多个单元格,则会将 RowAbsolute 和 ColumnAbsolute 应用于所有的行和列。
可选参数
有关可选参数的信息,请参见Office 解决方案中的可选参数。
示例
下面的代码示例创建一个 NamedRange,然后以四种格式显示 NamedRange 的地址。
此版本针对的是文档级自定义项。
    Private Sub DisplayAddress()
        Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
            = Me.Controls.AddNamedRange(Me.Range("A2", "C4"), _
            "namedRange1")
        ' The following code will display "$A$2:$C$4".
        MessageBox.Show(namedRange1.Address(True, True, _
            Excel.XlReferenceStyle.xlA1, False, ))
        ' The following code will display "$A2:$C4".
        MessageBox.Show(namedRange1.Address(False, True, _
            Excel.XlReferenceStyle.xlA1, False, ))
        ' The following code will display "R2C1:R4C3".
        MessageBox.Show(namedRange1.Address(True, True, _
            Excel.XlReferenceStyle.xlR1C1, False, ))
        ' The following code will display "R[-1]C[-2]:R[1]C".
        MessageBox.Show(namedRange1.Address(False, False, _
            Excel.XlReferenceStyle.xlR1C1, False, Me.Cells(3, 3)))
    End Sub
private void DisplayAddress()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A2","C4"],
        "namedRange1");
    // The following code will display "$A$2:$C$4".
    MessageBox.Show(namedRange1.Address[true, true,
        Excel.XlReferenceStyle.xlA1, false, missing]);
    // The following code will display "$A2:$C4".
    MessageBox.Show(namedRange1.Address[false, true,
        Excel.XlReferenceStyle.xlA1, false, missing]);
    // The following code will display "R2C1:R4C3".
    MessageBox.Show(namedRange1.Address[true, true,
        Excel.XlReferenceStyle.xlR1C1, false, missing]);
    // The following code will display "R[-1]C[-2]:R[1]C".
    MessageBox.Show(namedRange1.Address[false, false,
        Excel.XlReferenceStyle.xlR1C1, false, this.Cells[3, 3]]);
}
此版本针对的是应用程序级外接程序。
    Private Sub DisplayAddress()
        Dim NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet =
    Globals.ThisAddIn.Application.ActiveSheet
        Dim vstoWorksheet As Microsoft.Office.Tools.Excel.Worksheet =
                Globals.Factory.GetVstoObject(NativeWorksheet)
        Dim namedRange1 As NamedRange = vstoWorksheet.Controls.AddNamedRange( _
            vstoWorksheet.Range("A2", "C4"), "namedRange1")
        ' The following code will display "$A$2:$C$4".
        System.Windows.Forms.MessageBox.Show(namedRange1.Address(True, True, _
            Excel.XlReferenceStyle.xlA1, False, ))
        ' The following code will display "$A2:$C4".
        System.Windows.Forms.MessageBox.Show(namedRange1.Address(False, True, _
            Excel.XlReferenceStyle.xlA1, False, ))
        ' The following code will display "R2C1:R4C3".
        System.Windows.Forms.MessageBox.Show(namedRange1.Address(True, True, _
            Excel.XlReferenceStyle.xlR1C1, False, ))
        ' The following code will display "R[-1]C[-2]:R[1]C".
        System.Windows.Forms.MessageBox.Show(namedRange1.Address(False, False, _
            Excel.XlReferenceStyle.xlR1C1, False, vstoWorksheet.Cells(3, 3)))
    End Sub
private void DisplayAddress()
{
    Worksheet vstoWorksheet = 
        Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook.Worksheets[1]);
    NamedRange namedRange1 =
        vstoWorksheet.Controls.AddNamedRange(vstoWorksheet.Range["A2", "C4"],
        "namedRange1");
    // The following code will display "$A$2:$C$4".
    System.Windows.Forms.MessageBox.Show(namedRange1.Address[true, true,
        Excel.XlReferenceStyle.xlA1, false, missing]);
    // The following code will display "$A2:$C4".
    System.Windows.Forms.MessageBox.Show(namedRange1.Address[false, true,
        Excel.XlReferenceStyle.xlA1, false, missing]);
    // The following code will display "R2C1:R4C3".
    System.Windows.Forms.MessageBox.Show(namedRange1.Address[true, true,
        Excel.XlReferenceStyle.xlR1C1, false, missing]);
    // The following code will display "R[-1]C[-2]:R[1]C".
    System.Windows.Forms.MessageBox.Show(namedRange1.Address[false, false,
        Excel.XlReferenceStyle.xlR1C1, false, vstoWorksheet.Cells[3, 3]]);
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。