Share via


Metodo NamedRange.AutoFormat

Formatta automaticamente il controllo NamedRange utilizzando un formato predefinito.

Spazio dei nomi:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Sintassi

'Dichiarazione
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
)

Parametri

  • Number
    Tipo: System.Object
    true per includere i formati numerici nella Formattazione automatica.Il valore predefinito è true..
  • Font
    Tipo: System.Object
    true per includere i formati per il tipo di carattere nella Formattazione automatica.Il valore predefinito è true.
  • Alignment
    Tipo: System.Object
    true per includere l'allineamento nella Formattazione automatica.Il valore predefinito è true.
  • Border
    Tipo: System.Object
    true per includere i formati per il bordo nella Formattazione automatica.Il valore predefinito è true.
  • Pattern
    Tipo: System.Object
    true per includere i formati per il motivo nella Formattazione automatica.Il valore predefinito è true.
  • Width
    Tipo: System.Object
    true per includere la larghezza di colonna e l'altezza di riga nella Formattazione automatica.Il valore predefinito è true.

Valore restituito

Tipo: System.Object

Note

Se l'intervallo è a cella singola, questo metodo formatta anche l'area attiva circostante la cella.

Parametri facoltativi

Per informazioni sui parametri facoltativi, vedere Parametri facoltativi nelle soluzioni Office.

Esempi

Nell'esempio di codice riportato di seguito viene illustrato come impostare diverse caratteristiche di formattazione e visualizzazione di un controllo NamedRange denominato NamedRange1. In particolare, viene utilizzato il metodo AutoFormat per formattare NamedRange1 utilizzando il formato xlRangeAutoFormat3DEffects1.

Questo esempio è valido per una personalizzazione a livello di documento.

    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", missing, missing);
    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, missing);
    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();
    }
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

NamedRange Interfaccia

Spazio dei nomi Microsoft.Office.Tools.Excel