Share via


NamedRange.AutoFormat 方法

使用預先定義的格式,自動格式化 NamedRange 控制項。

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

語法

'宣告
Function AutoFormat ( _
    Format As XlRangeAutoFormat, _
    Number As Object, _
    Font As Object, _
    Alignment As Object, _
    Border As Object, _
    Pattern As Object, _
    Width As Object _
) As Object
Object AutoFormat(
    XlRangeAutoFormat Format,
    Object Number,
    Object Font,
    Object Alignment,
    Object Border,
    Object Pattern,
    Object Width
)

參數

  • Number
    型別:System.Object
    true 表示在 AutoFormat 中包含數值格式。預設值為 true.。
  • Font
    型別:System.Object
    true 表示在 AutoFormat 中包含字型格式。預設值是 true。
  • Alignment
    型別:System.Object
    true 表示在 AutoFormat 中包含對齊方式。預設值是 true。
  • Border
    型別:System.Object
    true 表示在 AutoFormat 中包含框線格式。預設值是 true。
  • Pattern
    型別:System.Object
    true 表示在 AutoFormat 中包含圖樣格式。預設值是 true。
  • Width
    型別:System.Object
    true 表示在 AutoFormat 中包含欄寬和列高。預設值是 true。

傳回值

型別:System.Object

備註

如果範圍是單一儲存格,則這個方法也會格式化儲存格周圍的現用區域。

選擇性參數

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

範例

下列程式碼範例會示範如何設定名稱為 NamedRange1 之 NamedRange 控制項的各種格式化和顯示特性。 請特別注意,這個範例使用 AutoFormat 方法,以 xlRangeAutoFormat3DEffects1 格式來格式化 NamedRange1。

這是示範文件層級自訂的範例。

    Private Sub SetRangeFormats()
        Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
            = Me.Controls.AddNamedRange(Me.Range("A1", "A5"), _
            "namedRange1")

        namedRange1.NoteText("This is a Formatting test", , )
        namedRange1.Value2 = "Martha"
        namedRange1.Font.Name = "Verdana"
        namedRange1.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
        namedRange1.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
        namedRange1.BorderAround(, Excel.XlBorderWeight.xlThick, _
            Excel.XlColorIndex.xlColorIndexAutomatic, )
        namedRange1.AutoFormat( _
            Excel.XlRangeAutoFormat.xlRangeAutoFormat3DEffects1, _
            True, False, True, False, True, True)

        If MessageBox.Show("Clear the formatting and notes?", _
            "Test", MessageBoxButtons.YesNo) = DialogResult.Yes Then
            namedRange1.ClearFormats()
            namedRange1.ClearNotes()
        End If
    End Sub

private void SetRangeFormats()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A5"],
        "namedRange1");

    namedRange1.NoteText("This is a Formatting test");
    namedRange1.Value2 = "Martha";
    namedRange1.Font.Name = "Verdana";
    namedRange1.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
    namedRange1.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
    namedRange1.BorderAround(missing, Excel.XlBorderWeight.xlThick, 
        Excel.XlColorIndex.xlColorIndexAutomatic);
    namedRange1.AutoFormat(Excel.XlRangeAutoFormat.xlRangeAutoFormat3DEffects1,
        true, false, true, false, true, true);

    if (MessageBox.Show("Clear the formatting and notes?", "Test",
        MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        namedRange1.ClearFormats();
        namedRange1.ClearNotes();
    }
}

.NET Framework 安全性

請參閱

參考

NamedRange 介面

Microsoft.Office.Tools.Excel 命名空間