Message-ID: <592901920.9987.1711708425681.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_9986_529271742.1711708425681" ------=_Part_9986_529271742.1711708425681 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Styles in ExcelWriter

Styles in ExcelWriter

ExcelWriter creates three style types:

=20 =20

All three style types derive from the Style class, and NamedStyle derive= s from GlobalStyle.

A style can be set or applied to cells, rows, columns,= ranges, and areas.

When a style is  set, the object to which the style is assigned acquires all of tha= t style's properties, including font properties and number formatting. When= a style is  applied, only the differences between the new style and existing s= tyle properties (assigned through the ExcelWriter API or in Microsoft Excel= ) will take effect.

For example, if the cell has a background color and the new style applie= d does not contain a background color, the cell's color will not be affecte= d. Note: Properties that were set on a pre-existing style in a workbook wil= l not be propogated to the object to which a new style is applied.

=20
=20 Icon=20
=20

Setting a style overwrites any pre-existing formatting on the cell, area= , or range. Applying a style merges the new style with the previous one.=20

=20
=20

To set a style, use the Style property or the SetStyle method. = To apply a style, call ApplyStyle. Both are accessible through the= following objects: Cell, Area, Range, RowProperties, and ColumnProperties.=

GlobalStyle

A GlobalStyle is global to a workbook. It can be set or app= lied to cells, rows, columns, areas, and ranges. When a GlobalStyle is= set (using the Style property), subsequent changes to the style a= ffect all cells on which the style was set. When a GlobalStyle is appli= ed (using the ApplyStyle method), subsequent changes to the style will= not affect cells to which the style was applied.

Unlike NamedStyles, Glob= alStyles are not stored in a collection, so they may be created, but not re= trieved. A GlobalStyle is not accessible after the workbook is saved.

To create a GlobalStyle, call Workbook.CreateStyle.

NamedStyle

The ExcelApplication object contains a collection of NamedStyles, which = - unlike GlobalStyles are accessible after the workbook is saved. This coll= ection includes Excel's built-in styles and any user-defined styles in a wo= rkbook opened with the ExcelApplication.Open method.

A NamedStyle is global to a workbook. It can be set or appl= ied to cells, rows, columns, areas, and ranges. When a NamedStyle is <= em>set (using the Style property), subsequent changes to the style aff= ect all cells on which the style was set. When a NamedStyle is retrieved fr= om an existing workbook and applied (using the ApplyStyle method),= subsequent changes to the style will not affect cells to which the style w= as applied.

To create a NamedStyle, call Workbook.CreateNamedStyle.

To return an existing NamedStyle, call Workbook.GetNamedStyle.

CellStyle

Every cell in an Excel workbook contains a unique cell style. This style= is exposed by ExcelWriter through the CellStyle class. Changes to a CellSt= yle affect only the cell that owns the style. A CellStyle may be set on another cell or group of cells, but this action clones the style. Cha= nges to the original CellStyle reference affect only the owning cell and ch= anges to the cloned CellStyle affect only the cell on which the style was s= et. If the style is set on a cell grouping object - such as an area, range,= row, or column - each cell in the grouping receives a unique clone of the = style.

CellStyles are accessed through Cell.Style.

Example

=20
ExcelApplication xla =3D new ExcelApplication();
Workbook wb =3D xla.Create(ExcelApplication.FileFormat.Xlsx);
Worksheet ws =3D wb.Worksheets[0];

//--- Write some random data into the cells to be stylized
System.Random rand =3D new System.Random();
for(int iRow =3D 0; iRow < 24; iRow++)
          for(int iCol =3D 0; iCol < 3; iCol++)
                    ws.Cells[iRow, iCol].Value =3D rand.Next(100);

ws.Cells[24, 0].Formula =3D "=3DSUM(A1:A24)";
ws.Cells[24, 1].Formula =3D "=3DSUM(B1:B24)";
ws.Cells[24, 2].Formula =3D "=3DSUM(C1:C24)";

//--- This GlobalStyle, styleMoneyFormat, will be used to apply currency
//--- stylization to workbook values.
Style styleMoneyFormat =3D wb.CreateStyle();
styleMoneyFormat.NumberFormat =3D "$#,##.00";

//--- styleBold represents a bold-faced font.
Style styleBold =3D wb.CreateStyle();
styleBold.Font.Bold =3D true;

//--- Set Style on an Area of cells
//--- The SetStyle method sets a base style
//--- and overwrites all existing style attributes
Area areaData =3D ws.CreateArea("A1:C25");
areaData.SetStyle(styleMoneyFormat);

//--- ApplyStyle overlays a style with an existing
//--- style, changing only the attributes that have
//--- been defined in the applied style
Area areaTotalRow =3D ws.CreateArea("A25:C25");
areaTotalRow.ApplyStyle(styleBold);

xla.Save(wb, "Styles.xlsx");

=20

Code = Example: ExcelApplication Basic Steps

This sample shows many of the core features of ExcelApplication, includi= ng the use of Styles.

[C#] | [VB.NET]

------=_Part_9986_529271742.1711708425681--