Condividi tramite


WorkbookBase.Styles Property

Definition

Gets a Styles collection that represents all the styles in the workbook.

public:
 property Microsoft::Office::Interop::Excel::Styles ^ Styles { Microsoft::Office::Interop::Excel::Styles ^ get(); };
public Microsoft.Office.Interop.Excel.Styles Styles { get; }
member this.Styles : Microsoft.Office.Interop.Excel.Styles
Public ReadOnly Property Styles As Styles

Property Value

A Styles collection that represents all the styles in the workbook.

Examples

The following code example uses the Styles property to adjust some of the properties of each Microsoft.Office.Interop.Excel.Style in the workbook, including text wrapping, vertical and horizontal alignment, and hiding formulas.

This example is for a document-level customization.

private void SetWorkbookStyles()
{
    for (int i = 1; i <= this.Styles.Count; i++)
    {
        this.Styles[i].WrapText = true;
        this.Styles[i].VerticalAlignment = Excel.XlVAlign.xlVAlignTop;
        this.Styles[i].HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
        this.Styles[i].FormulaHidden = true;
        Globals.Sheet1.Range["A" + i].Value2 =
            "Adjusted style " + this.Styles[i].Name;
    }
}
Private Sub SetWorkbookStyles()
    Dim i As Integer
    For i = 1 To Me.Styles.Count
        Me.Styles(i).WrapText = True
        Me.Styles(i).VerticalAlignment = Excel.XlVAlign.xlVAlignTop
        Me.Styles(i).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft
        Me.Styles(i).FormulaHidden = True
        Globals.Sheet1.Range("A" & i).Value2 = _
            "Adjusted style " & Me.Styles(i).Name
    Next i
End Sub

Applies to