Formatting Number Formats
Output: FormattingNumberFormats.xlsx
public void Run()
{
var workbook = new Workbook();
var worksheet = workbook.Worksheets[0];
worksheet.Columns[0].WidthCharacters = 20;
double doubleValue = 1234.5678;
worksheet["A1"].Value = "General";
worksheet["A2"].Value = "'0";
worksheet["A3"].Value = "'0.00";
worksheet["A4"].Value = "#,##0";
worksheet["A5"].Value = "#,##0.00";
worksheet["B1"].Value = doubleValue;
worksheet["B2"].Value = doubleValue;
worksheet["B3"].Value = doubleValue;
worksheet["B4"].Value = doubleValue;
worksheet["B5"].Value = doubleValue;
worksheet["B1"].Format = Spreadsheet.Office.Model.Formats.General;
worksheet["B2"].Format = new NumberFormat("0");
worksheet["B3"].Format = new NumberFormat("0.00");
worksheet["B4"].Format = new NumberFormat("#,##0");
worksheet["B5"].Format = new NumberFormat("#,##0.00");
worksheet["A7"].Value = "#,##0.00;[Red]-#,##0.00";
worksheet["B7"].Value = doubleValue * -1;
worksheet["B7"].Format = new NumberFormat("#,##0.00;[Red]-#,##0.00");
worksheet["A9"].Value = "Scientific 0.E+00";
worksheet["B9"].Value = doubleValue;
worksheet["B9"].Format = new NumberFormat("0.E+00");
worksheet["A10"].Value = "Scientific 0.00E+0";
worksheet["B10"].Value = doubleValue;
worksheet["B10"].Format = new NumberFormat("0.00E+0");
worksheet["A12"].Value = "Percent 0%";
worksheet["B12"].Value = doubleValue;
worksheet["B12"].Format = new NumberFormat("0%");
worksheet["A13"].Value = "Percent 0.00%";
worksheet["B13"].Value = doubleValue;
worksheet["B13"].Format = new NumberFormat("0.00%");
workbook.SaveAs("FormattingNumberFormats.xlsx");
}