WorksheetBase.Rows 屬性
取得 Range 物件,該物件表示工作表上的一個或多個列。
命名空間: Microsoft.Office.Tools.Excel
組件: Microsoft.Office.Tools.Excel.v4.0.Utilities (在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)
語法
'宣告
Public ReadOnly Property Rows As Range
Get
public Range Rows { get; }
屬性值
型別:Microsoft.Office.Interop.Excel.Range
Range 物件,該物件表示工作表上的一個或多個列。
備註
不搭配參數使用時,這個屬性會傳回 Range 物件,其中包含工作表上所有的資料列。
這個屬性可與下列選擇性參數搭配使用,以取得工作表上特定的資料列。 如果您使用這個屬性搭配參數,傳回的值會是必須轉型成 Range 的物件。
參數 |
描述 |
---|---|
RowIndex |
所要取得的一個或多個資料列索引。 若要取得單一資料列,請傳遞指定您要取得資料列索引的整數。 資料列索引是從 1 開始。 若要取得多個連續的資料列,請使用格式 "first row:last row" 傳遞字串。 例如,要取得資料列 1 到 5,傳遞 "1:5"。 |
ColumnIndex |
請勿使用這個參數。 如果您嘗試將值傳遞給這個參數,這個屬性會擲回 COMException。 |
範例
下列程式碼範例會使用 Rows 屬性來設定工作表上前五個資料列中所有儲存格之字型的色彩、名稱、大小及粗細。
這是示範文件層級自訂的範例。 若要執行這個程式碼,請將它複製到專案中的其中一個工作表類別。
Private Sub SetRowsFont()
Dim fillRows As Excel.Range = TryCast(Me.Rows("1:5"), Excel.Range)
With fillRows.Font
' Set the font color to blue (RGB value 00 00 FF), and set other font properties.
.Color = &HFF0000
.Name = "Arial"
.Size = 14
.Bold = False
End With
' Test the changes by writing a value to all the row cells.
fillRows.Value2 = "This is a test"
End Sub
private void SetRowsFont()
{
Excel.Range fillRows = (Excel.Range)this.Rows["1:5", missing];
Excel.Font rowsFont = fillRows.Font;
// Set the font color to blue (RGB value 00 00 FF), and set other font properties.
rowsFont.Color = 0xFF0000;
rowsFont.Name = "Arial";
rowsFont.Size = 14;
rowsFont.Bold = false;
// Test the changes by writing a value to all the row cells.
fillRows.Value2 = "This is a test";
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。