This documentation is archived and is not being maintained.

Workbook.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 (in microsoft.office.tools.excel.dll)

public virtual Styles Styles { get; }

Property Value

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

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.

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;
    }
}

Show: