Repository navigation
Formatting and styling
This page has moved. The current version of this page is at https://epplussoftware.com/docs/styling/formatting-and-styling/. The EPPlus documentation is no longer updated in this wiki; please use the EPPlus guides and update your bookmarks.
Cell styling is accessed by the Style property of a range. You can easily style your spreadsheets by using the indexer of the Cells property described above.
Let's say you want to set the numberformat of a range...
worksheet.Cells["C2:C5"].Style.Numberformat.Format = "#,##0";
...or you want to set the header row to bold and dark background and white font...
using (var range = worksheet.Cells[1, 1, 5, 1]) // Address "A1:A5"
{
range.Style.Font.Bold = true;
range.Style.Fill.PatternType = ExcelFillStyle.Solid;
range.Style.Fill.BackgroundColor.SetColor(Color.DarkBlue);
range.Style.Font.Color.SetColor(Color.White);
}
To see some real code showing cell access and styling, look into the sample project, for example Sample 1.1-C# or Sample 1.1-VB.
You can also create your own named styles, using the Workbook.Styles.CreateNamedStyle method and the ExcelRange.StyleName property. As shown in Sample 3.4-C# or Sample 3.4-VB...
// Add a HyperLink to the statistics sheet.
var namedStyle = pck.Workbook.Styles.CreateNamedStyle("HyperLink");
namedStyle.Style.Font.UnderLine = true;
namedStyle.Style.Font.Color.SetColor(Color.Blue);
ws.Cells["K13"].Hyperlink = new ExcelHyperLink("Statistics!A1", "Statistics");
ws.Cells["K13"].StyleName = "HyperLink";
Looking for Regional/Culture-Specific Numberformats? Look here!
Number formats in EPPlus use the OOXML number format style. If you are unsure what format to use, please try this to get a specific format:
- Open a new Excel document and format a cell to the number format you want to apply.
- Save the workbook.
From here you can either open the workbook using EPPlus to see the number format for the cell or extract the package as described here:
- Rename the workbook to *.zip
- Extract the zip package.
- Open the file
xl\styles.xmlin the folder where you extracted the package. - Number formats can be found under the
numFmtselement in the xml file.
OOXML has several built-in number formats:
| Id | Format |
|---|---|
| 0 | General |
| 1 | 0 |
| 2 | 0.00 |
| 3 | #,##0 |
| 4 | #,##0.00 |
| 9 | 0% |
| 10 | 0.00% |
| 11 | 0.00E+00 |
| 12 | # ?/? |
| 13 | # ??/?? |
| 14 | mm-dd-yy |
| 15 | d-mmm-yy |
| 16 | d-mmm |
| 17 | mmm-yy |
| 18 | h:mm AM/PM |
| 19 | h:mm:ss AM/PM |
| 20 | h:mm |
| 21 | h:mm:ss |
| 22 | m/d/yy h:mm |
| 37 | #,##0 ;(#,##0) |
| 38 | #,##0 ;Red |
| 39 | #,##0.00;(#,##0.00) |
| 40 | #,##0.00;Red |
| 45 | mm:ss |
| 46 | [h]:mm:ss |
| 47 | mmss.0 |
| 48 | ##0.0E+0 |
| 49 | @ |
Always use the number format. EPPlus will translate formats to the corresponding number format id.
- The Text Property (Regional Number Formats)
- Styling Sample-C# or Styling Sample-VB
EPPlus Software AB - https://epplussoftware.com
- What is new in EPPlus 5+
- Breaking Changes in EPPlus 5
- Breaking Changes in EPPlus 6
- Breaking Changes in EPPlus 7
- Breaking Changes in EPPlus 8
- Addressing a worksheet
- Dimension/Used range
- Copying ranges/sheets
- Insert/Delete
- Filling ranges
- Sorting ranges
- Taking and skipping columns/rows
- Data validation
- Comments
- Freeze and Split Panes
- Header and Footer
- Hyperlinks
- Autofit columns
- Grouping and Ungrouping Rows and Columns
- Formatting and styling
- The ExcelRange.Text property
- Conditional formatting
- Using Themes
- Working with custom named table- or slicer- styles
-
Formula Calculation
- Security considerations
- Circular references
- Referencing tables in formulas
- Supported Functions
- Dynamic array formulas
- Legacy array formulas
- Lambda functions
- Regression analysis functions
- Custom functions for calculations
- Function prefixes
- Precision as Displayed
- Cancelling a calculation
- Trim reference operator
- Working with filters
- Working with slicers
- Working with External Workbooks