The proper formatting of worksheet cells improves document appearance, and allows end-users to read, find and understand data more easily. Cell formatting includes a variety of features such as multiple settings for font, font size, character style (bold, italics, underlined), text alignment, background and foreground colors, etc. This document explains the concepts of Cell StylesDirect Cell FormattingStyle Flags and Rich Text Formatting
A style is a named set of predefined cell format characteristics (font settings, number format, content alignment, cell borders, fill color, etc.). When applying a style, all format settings are applied to a cell or cell range in a single step.
A workbook maintains all available styles in a StyleCollection collection, which is accessed via the IWorkbook.Styles property. By default, this collection contains a set of built-in cell styles similar to Microsoft® Excel® (including the Normal style, which is applied to all unformatted cells in the workbook by default). Identifiers of all built-in styles are listed by the BuiltInStyleId enumerator.
You can do the following to manage the workbook's collection of cell styles.
To change cell appearance, you can not only apply a style, but also set the required format characteristics directly for an individual cell or cell range. This is called direct cell formatting. In SpreadsheetControl, direct cell formatting options are available via the Ribbon interface (the Home tab) or in the Format Cells dialog.
Thus, a Cell or CellRange object's properties inherited from the Formatting interface provide access to the actual formatting specified for a cell or range of cells (including characteristics defined by an applied style and direct cell formatting attributes).
As mentioned above, the appearance of a cell is determined by the format settings of the applied style and the format settings of the cell itself. Each of these formatting types provides a set of flags (Formatting.Flags). Each flag corresponds to a specific group of format attributes, and indicates whether to use the attributes specified in the applied style or the attributes specified directly for the cell.
Horizontal and vertical alignment of cell content, indentation and text wrap.
A cell in a worksheet can contain rich formatted text specified by the RichTextString object. Rich text is comprised of one or more text regions (or text runs), each with its own set of font characteristics. An individual text run is defined by the RichTextRun object and stored in the RichTextString.Runs collection.
The WPF Spreadsheet control does not display, print or export (to PDF) rich format settings applied to a cell. However, it saves rich text to a document, so that you can view and print the document in Microsoft® Excel® or another spreadsheet application.
You can apply rich formatting to cell text as follows: