ExcelWriter creates three style types:
...
Table of Contents |
---|
...
|
...
|
All three style types derive from the Style class, and NamedStyle derives from GlobalStyle.
...
CellStyles are accessed through Cell.Style.
Example
Code Block | ||||
---|---|---|---|---|
| ||||
ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Create(ExcelApplication.FileFormat.Xlsx);
Worksheet ws = wb.Worksheets[0];
//--- Write some random data into the cells to be stylized
System.Random rand = new System.Random();
for(int iRow = 0; iRow < 24; iRow++)
for(int iCol = 0; iCol < 3; iCol++)
ws.Cells[iRow, iCol].Value = rand.Next(100);
ws.Cells[24, 0].Formula = "=SUM(A1:A24)";
ws.Cells[24, 1].Formula = "=SUM(B1:B24)";
ws.Cells[24, 2].Formula = "=SUM(C1:C24)";
//--- This GlobalStyle, styleMoneyFormat, will be used to apply currency
//--- stylization to workbook values.
Style styleMoneyFormat = wb.CreateStyle();
styleMoneyFormat.NumberFormat = "$#,##.00";
//--- styleBold represents a bold-faced font.
Style styleBold = wb.CreateStyle();
styleBold.Font.Bold = true;
//--- Set Style on an Area of cells
//--- The SetStyle method sets a base style
//--- and overwrites all existing style attributes
Area areaData = 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 = ws.CreateArea("A25:C25");
areaTotalRow.ApplyStyle(styleBold);
xla.Save(wb, "Styles.xlsx");
|
Code
...
Example: ExcelApplication Basic Steps
This sample shows many of the core features of ExcelApplication, including the use of Styles.
...