Worksheet.Range 屬性

取得 Microsoft.Office.Interop.Excel.Range 物件,表示某個儲存格或儲存格範圍。

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

語法

'宣告
ReadOnly Property Range As Worksheet_RangeType
Worksheet_RangeType Range { get; }

屬性值

型別:Microsoft.Office.Tools.Excel.Worksheet_RangeType
Microsoft.Office.Interop.Excel.Range 物件,表示某個儲存格或儲存格範圍。

備註

Range 屬性的用意是要與下列參數一起使用。

參數

描述

Cell1

應用程式語言中,A1 樣式標記內的範圍名稱。 該名稱可包含範圍運算子 (冒號)、交集運算子 (空格) 或等位運算子 (逗號)。 另外也可以包含貨幣符號,但該符號會被忽略。 您可以在範圍中的任何部分使用本機定義的名稱。 如果您使用名稱,則這個名稱會被視為應用程式語言的一部分。 這是必要參數。

Cell2

範圍右下角的儲存格。 這可以是包含單一儲存格、整欄、整列的 Microsoft.Office.Interop.Excel.Range,也可以是以應用程式語言為單一儲存格命名的字串。 這個參數是一個選擇性項目。

如果使用未指定任何參數的 Range 屬性,則它會傳回 Worksheet_RangeType 物件,該物件並不適合直接從您的程式碼使用。

選擇性參數

如需選擇性參數的詳細資訊,請參閱Office 方案中的選擇性參數

範例

下列程式碼範例示範使用 Range 屬性存取單一個或多個儲存格的不同方法。

這是應用程式層級增益集的範例。

Private Sub CompareRangeUsage()

    Dim NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet =
        Globals.ThisAddIn.Application.ActiveWorksheet("Sheet1")
    Dim vstoWorksheet As Microsoft.Office.Tools.Excel.Worksheet =
        Globals.Factory.GetVstoObject(NativeWorksheet)

    ' The following line of code specifies a single cell.
    vstoWorksheet.Range("A1").Value2 = "Range 1"

    ' The following line of code specifies multiple cells.
    vstoWorksheet.Range("A3", "B4").Value2 = "Range 2"

    ' The following line of code uses an Excel.Range for 
    ' the second parameter of the Range property.
    Dim range1 As Excel.Range = vstoWorksheet.Range("C8")
    vstoWorksheet.Range("A6", range1).Value2 = "Range 3"
End Sub
private void CompareRangeUsage()
{                      
    Worksheet vstoWorksheet = Globals.Factory.GetVstoObject(
        this.Application.ActiveWorkbook.Worksheets[1]);
    // The following line of code specifies a single cell.
    vstoWorksheet.Range["A1"].Value2 = "Range 1";

    // The following line of code specifies multiple cells.
    vstoWorksheet.Range["A3", "B4"].Value2 = "Range 2";

    // The following line of code uses an Excel.Range for 
    // the second parameter of the Range property.
    Excel.Range range1 = vstoWorksheet.Range["C8"];
    vstoWorksheet.Range["A6", range1].Value2 = "Range 3";
}

.NET Framework 安全性

請參閱

參考

Worksheet 介面

Microsoft.Office.Tools.Excel 命名空間