...
CellStyles are accessed through Cell.Style.
Example
Code Block | ||||
---|---|---|---|---|
| ||||
using SoftArtisans.OfficeWriter.ExcelWriter; class StylesDemo : System.Web.UI.Page { protected void Page_Load(object sender, System.EventArgs e) { ExcelApplication xla = new ExcelApplication(ExcelApplication.FileFormat.Xlsx); Workbook wb = xla.Create(); 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, Page.Response, "Styles.xlsxlsx", false); } } } } |
Code Eample: ExcelApplication Basic Steps
...