Programmer's Reference >
ExcelApplication API >
Style
The Style Object
ExcelWriter has three style types: CellStyle , GlobalStyle , and NamedStyle . All three types derive from the Style class, and NamedStyle derives from GlobalStyle . - Styles can be both "set" and "applied" to ranges, areas, cells, rows, and columns.
- To bind a style to a cell or set of cells, call
ApplyStyle or applyStyle . Both are accessible through the following objects: Cell , Area , Range , RowProperties , and ColumnProperties . - When a style is "set", it is cloned and the object on which it is "set" acquires all of that style's properties, including font proprties and number formatting
- When a style is applied, only the differences between the new style and style properties previously assigned to the cell (through the ExcelWriter API or in Microsoft Excel) will take effect. For example, if the cell has a background color and the new style applied does not contain a background color, the cell's color will not be affected. Note : Properties that were set on a pre-existing style in a workbook will not be propogated to the object to which the style is "applied".
You cannot create a CellStyle, only manipulate existing ones as part of the objects they apply to. To create a GlobalStyle , use Workbook.CreateStyle() . To create a NamedStyle , use Workbook.CreateNamedStyle() . To get a NamedStyle from an existing document, use Workbook.GetNamedStyle() .
Examples:
[csharp]
// Open existing spreadsheet
ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Open(@"C:\MySpreadsheet.xls");
// Create GlobalStyle
Style global = wb.CreateStyle();
// Create NamedStyle
Style newNamed = wb.CreateNamedStyle("MyStyle");
// Get NamedStyle
Style existingNamed = wb.GetNamedStyle("ExistingStyle");
[vbnet]
' Open existing spreadsheet
Dim xla As New ExcelApplication()
Dim wb As Workbook = xla.Open("C:\MySpreadsheet")
' Create GlobalStyle
Dim global As Style = wb.CreateStyle()
' Create NamedStyle
Dim newNamed As Style = wb.CreateNamedStyle("MyStyle")
' Get NamedStyle
Dim existingNamed As Style = wb.GetNamedStyle("ExistingStyle")
Style Enumerations
Style Properties
Property |
Type |
Access |
Description |
BackgroundColor |
Color
|
read write |
Sets or returns the background color for cells
|
Border |
Border
|
read |
Returns a Border object for the style
|
CellLocked |
boolean
|
read write |
Sets or returns whether a cell will be locked in a protected worksheet
|
Font |
Font
|
read write |
Sets or returns the Font object that defines the font for this style
|
ForegroundColor |
Color
|
read write |
Sets or returns a foreground color for cells
|
HideFormulas |
boolean
|
read write |
Sets or returns whether formulas or their calculated results will be displayed in a protected worksheet
|
HorizontalAlignment |
Style.HAlign
|
read write |
Sets or returns the horizontal alignment of text within cells
|
IndentLevel |
int
|
read write |
Sets or returns level of indentation of the contents within the cell
|
JustifyDistributed |
boolean
|
read write |
Sets or returns the whether the text will be justfied horizontally, when the Horizontal Alignment is set to Distributed
|
NumberFormat |
String
|
read write |
Sets or returns the number format string used for formatting of numbers and dates
|
Orientation |
int
|
read write |
Sets or returns the angle that text is displayed at, as a value between -90 and 90
|
Pattern |
Pattern
|
read write |
Sets or returns a pattern applied to cells
|
ShrinkToFit |
boolean
|
read write |
Sets or returns whether text in a cell should be reduced in size to fit within the cell's width
|
TextDirection |
Style.TextDir
|
read write |
Sets or returns the direction of the text with in the cells
|
VerticalAlignment |
Style.VAlign
|
read write |
Sets or returns the vertical alignment of text within cells
|
WrapText |
boolean
|
read write |
Sets or returns if text that is larger than the width of the cell will be wrapped, increasing the height of a cell
|
This object does not have any methods defined.
Copyright 2005 © SoftArtisans, Inc. All Rights Reserved.
|