Udostępnij za pośrednictwem


WorkbookBase.Styles Property

Gets a Microsoft.Office.Interop.Excel.Styles collection that represents all the styles in the workbook.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
Public ReadOnly Property Styles As Styles
    Get
public Styles Styles { get; }

Property Value

Type: Microsoft.Office.Interop.Excel.Styles
A Microsoft.Office.Interop.Excel.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 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
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, missing].Value2 =
            "Adjusted style " + this.Styles[i].Name;
    }
}

.NET Framework Security

See Also

Reference

WorkbookBase Class

Microsoft.Office.Tools.Excel Namespace