How to format a cell as Number Accounting category using ClosedXML?

The number format is:
_ * # ##0.00_ ;_ * -# ##0.00_ ;_ * "-"??_ ;_ @_
And set the NumberFormatId to 43.
You can get the number format by using Excel. Style the cell as you want it and then go to Custom number format. The number format will display there.
In ClosedXML, you can use it like this (be careful to escape the quotation marks):
using (var wb = new XLWorkbook())
{
var ws = wb.AddWorksheet("Sheet1");
var cell = ws.FirstCell();
cell.Value = 0.0;
cell.DataType = XLDataType.Number;
cell.Style.NumberFormat.Format = "_ * # ##0.00_ ;_ * -# ##0.00_ ;_ * \"-\"??_ ;_ @_ ";
cell.Style.NumberFormat.SetNumberFormatId(43);
wb.SaveAs("test.xlsx");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With