Message-ID: <343620197.9761.1711701981201.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_9760_540628722.1711701981201" ------=_Part_9760_540628722.1711701981201 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
ExcelWriter creates three style types: GlobalStyle, NamedStyle, =
and CellStyle. All three style type=
s derive from the Style class, and GlobalStyle
.
public sealed class NamedStyle : GlobalStyle=20
Public NotInheritable Class NamedStyle =09=09Inherits GlobalStyle=20
A style can be set or= applied to cells, rows,= columns, ranges, and areas. When a style is set , it is cloned and the object to which the style i= s assigned acquires all of that style's properties, including font proprtie= s and number formatting. When a style is applied , only the differences between the new style and e= xisting style properties (assigned through the ExcelWriter API or in Micros= oft Excel) will take effect. For example, if the cell has a background colo= r and the new style applied does not contain a background color, the cell's= color will not be affected. However, if the new style includes a backgroun= d color, it will replace the existing background color of the cell.
=20The ExcelApp=
lication object contains a collection of NamedStyle
s, whi=
ch - unlike GlobalStyle
s are accessible after the workbook is=
saved. This allows you to dynamically create a template, save it to disk, =
re-open it to populate it with data, and then apply your newly-created styl=
e. This collection of NamedStyle
s includes Excel's built-in s=
tyles (such as the NORMAL style) and any user-defined styles in a workbook =
opened with the ExcelApplication object.
To create a NamedStyle
, call Workbook.CreateNamedStyle.
To return a NamedStyle
, call Workbook.GetNamedStyle.
ExcelApplication xla =3D new ExcelApplication(); Workbook wb =3D xla.Create(); //--- Create a named style. Style myItalicStyle =3D wb.CreateNamedStyle("ItalicStyle&quo= t;); //--- Turn on italics for the named style. myGlobalStyle.Font.Italics =3D true; //--- Get a "total" cell Cell totalCell =3D wb.Worksheets[0].Cells[4, 4]; //--- Check its value and apply style if necessary if(totalCell.Value > TARGET_TOTAL_VALUE) totalCell.ApplyStyle(myItalicStyle);=20
Dim xla As New ExcelApplication() Workbook wb =3D xla.Create() '--- Create a named style. Dim myItalicStyle As Style =3D wb.CreateNamedStyle("ItalicSt= yle") '--- Turn on italics for the named style myGlobalStyle.Font.Italics =3D True '--- Get a "total" cell Dim totalCall As Cell =3D wb.Worksheets(0).Cells(4, 4) '--- Check its value and apply style if necessary If totalCell.Value > TARGET_TOTAL_VALUE Then totalCell.ApplyStyle(myItalicStyle) End If=20
Name | =20
Description | =20
---|---|
=20 | Returns the style's name. This can be used to ac= cess the style later, and will appear in the Styles dialog in Excel. | = =20