Skip to content

Styles NumberFormat

Francois Botha edited this page Nov 7, 2018 · 5 revisions

Styles_NumberFormat.jpg

var workbook = new XLWorkbook();
var ws = workbook.Worksheets.Add("Style NumberFormat");

var co = 2;
var ro = 1;

// Using a custom format
ws.Cell(++ro, co).Value = "123456.789";
ws.Cell(ro, co).Style.NumberFormat.Format = "$ #,##0.00";

ws.Cell(++ro, co).Value = "12.345";
ws.Cell(ro, co).Style.NumberFormat.Format = "0000";

// Using a OpenXML's predefined formats
ws.Cell(++ro, co).Value = "12.345";
ws.Cell(ro, co).Style.NumberFormat.NumberFormatId = 3;

// Use XLPredefinedFormat enum
ws.Cell(++ro, co).Value = "123456789123";
ws.Cell(ro, co).Style.NumberFormat.SetNumberFormatId((int)XLPredefinedFormat.Number.Integer);

ws.Column(co).AdjustToContents();

workbook.SaveAs("StylesNumberFormat.xlsx");

For more information on NumberFormatId please see NumberFormatId Lookup Table.

FAQ

Examples

Real world scenarios

Time Savers

Performance and Memory

Misc

Inserting Data/Tables

Styles

Ranges

Rows

Columns

Page Setup (Print Options)

AutoFilters

Comments

Dev docs

Clone this wiki locally