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。默认值为 true.
  • Font
    类型:System.Object
    如果在自动套用格式中包括字体格式,则为 true。默认值为 true。
  • Alignment
    类型:System.Object
    如果在自动套用格式中包括对齐方式,则为 true。默认值为 true。
  • Border
    类型:System.Object
    如果在自动套用格式中包括边框格式,则为 true。默认值为 true。
  • Pattern
    类型:System.Object
    如果在自动套用格式中包括模式格式,则为 true。默认值为 true。
  • Width
    类型:System.Object
    如果在自动套用格式中包括列宽和行高,则为 true。默认值为 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 命名空间