Metoda NamedRange.AutoFormat —
Automatycznie formatuje NamedRange kontroli, przy użyciu formatu wstępnie zdefiniowanego.
Przestrzeń nazw: Microsoft.Office.Tools.Excel
Zestaw: Microsoft.Office.Tools.Excel (w Microsoft.Office.Tools.Excel.dll)
Składnia
'Deklaracja
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
)
Parametry
- Format
Typ: Microsoft.Office.Interop.Excel.XlRangeAutoFormat
Może być jednym z następujących XlRangeAutoFormat stałych:
xlRangeAutoFormat3DEffects1
xlRangeAutoFormat3DEffects2
xlRangeAutoFormatAccounting1
xlRangeAutoFormatAccounting2
xlRangeAutoFormatAccounting3
xlRangeAutoFormatAccounting4
xlRangeAutoFormatClassic1
xlRangeAutoFormatClassic2
xlRangeAutoFormatClassic3
xlRangeAutoFormatClassicPivotTable
xlRangeAutoFormatColor1
xlRangeAutoFormatColor2
xlRangeAutoFormatColor3
xlRangeAutoFormatList1
xlRangeAutoFormatList2
xlRangeAutoFormatList3
xlRangeAutoFormatLocalFormat1
xlRangeAutoFormatLocalFormat2
xlRangeAutoFormatLocalFormat3
xlRangeAutoFormatLocalFormat4
xlRangeAutoFormatNone
xlRangeAutoFormatPTNone
xlRangeAutoFormatReport1
xlRangeAutoFormatReport10
xlRangeAutoFormatReport2
xlRangeAutoFormatReport3
xlRangeAutoFormatReport4
xlRangeAutoFormatReport5
xlRangeAutoFormatReport6
xlRangeAutoFormatReport7
xlRangeAutoFormatReport8
xlRangeAutoFormatReport9
xlRangeAutoFormatSimple
xlRangeAutoFormatTable1
xlRangeAutoFormatTable10
xlRangeAutoFormatTable2
xlRangeAutoFormatTable3
xlRangeAutoFormatTable4
xlRangeAutoFormatTable5
xlRangeAutoFormatTable6
xlRangeAutoFormatTable7
xlRangeAutoFormatTable8
xlRangeAutoFormatTable9
Stała domyślną jest xlRangeAutoFormatClassic1.
Niektóre z tych stałych mogą być niedostępne, w zależności od języka pomocy technicznej (USAAngielski, na przykład) zaznaczone lub zainstalowany.
- Number
Typ: System.Object
true Aby dołączyć formaty liczbowe Autoformatowanie.Wartość domyślna to true.
- Font
Typ: System.Object
true Aby dołączyć formaty czcionek Autoformatowanie.Wartością domyślną jest true.
- Alignment
Typ: System.Object
true Aby dołączyć wyrównanie Autoformatowanie.Wartością domyślną jest true.
- Border
Typ: System.Object
true Aby objąć obramowanie formaty Autoformatowanie.Wartością domyślną jest true.
- Pattern
Typ: System.Object
true Aby objąć formaty wzór Autoformatowanie.Wartością domyślną jest true.
- Width
Typ: System.Object
true Aby dołączyć kolumny szerokości i wysokości wiersza Autoformatowanie.Wartością domyślną jest true.
Wartość zwracana
Typ: System.Object
Uwagi
Jeśli zakres znajduje się jedną komórkę, Metoda ta również formatuje aktywnego regionu otaczające komórki.
Parametry opcjonalne
Informacje na temat parametrów opcjonalnych, zobacz Parametry opcjonalne w rozwiązaniach Office.
Przykłady
Poniższy przykład kodu demonstruje sposób ustawiania różnych formatowania i wyświetlania właściwości NamedRange formantu niezwiązanego o nazwie NamedRange1.W szczególności, w tym przykładzie użyto AutoFormat metodę, sformatować NamedRange1 za pomocą xlRangeAutoFormat3DEffects1 format.
W tym przykładzie jest dla dostosowania poziomu dokumentu.
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();
}
}
Zabezpieczenia programu .NET Framework
- Pełne zaufanie do bezpośredniego wywołującego. Tego elementu członkowskiego nie można używać w kodzie częściowo zaufanym. Aby uzyskać więcej informacji, zobacz Używanie bibliotek pochodzących z częściowo zaufanego kodu.