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