NamedRange.AutoFormat Method
Automatically formats the NamedRange control, using a predefined format.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)
Syntax
'Declaration
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
)
Parameters
Format
Type: Microsoft.Office.Interop.Excel.XlRangeAutoFormatCan be one of the following XlRangeAutoFormat constants:
xlRangeAutoFormatClassicPivotTable
The default constant is xlRangeAutoFormatClassic1.
Some of these constants might not be available to you, depending on the language support (U.S. English, for example) that you selected or installed.
Number
Type: System.Objecttrue to include number formats in the AutoFormat. The default value is true.
Font
Type: System.Objecttrue to include font formats in the AutoFormat. The default value is true.
Alignment
Type: System.Objecttrue to include alignment in the AutoFormat. The default value is true.
Border
Type: System.Objecttrue to include border formats in the AutoFormat. The default value is true.
Pattern
Type: System.Objecttrue to include pattern formats in the AutoFormat. The default value is true.
Width
Type: System.Objecttrue to include column width and row height in the AutoFormat. The default value is true.
Return Value
Type: System.Object
Remarks
If the range is a single cell, this method also formats the active region surrounding the cell.
Optional Parameters
For information on optional parameters, see Optional Parameters in Office Solutions.
Examples
The following code example demonstrates how to set a variety of formatting and display characteristics of a NamedRange control named NamedRange1. In particular, this example uses the AutoFormat method to format NamedRange1 using the xlRangeAutoFormat3DEffects1 format.
This example is for a document-level customization.
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 Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.