Search code examples
excelformattingnumber-formattingepplusaccounting

How can I set contents of a spreadsheet cell to Accounting format with EPPlus?


I need to set the contents of certain columns to Accounting format.

This attempt:

public static readonly string NUMBER_FORMAT_ACCOUNTING = "$";
. . .
bidPriceCell.Style.Numberformat.Format = NUMBER_FORMAT_ACCOUNTING;

...simply gives "$" and "-$" as the values.

This attempt:

public static readonly string NUMBER_FORMAT_ACCOUNTING = "$0.00";
. . .
bidPriceCell.Style.Numberformat.Format = NUMBER_FORMAT_ACCOUNTING;

...gives me values such as, "$24.09" and "-$0.91"

What the user wants is space between the dollar sign and the value, and parens around negative values, such as "$ 24.09" and "$ (0.91)"

What string do I need to assign the Numberformat.Format property for this to work?


Solution

  • Found the answer from Wildpinkler here, which is:

    @"_(""$""* #,##0.00_);_(""$""* \(#,##0.00\);_(""$""* ""-""??_);_(@_)";
    

    ...so that the following works:

    public static readonly  String NUMBER_FORMAT_ACCOUNTING = @"_(""$""* #,##0.00_);_(""$""* \(#,##0.00\);_(""$""* ""-""??_);_(@_)";
    . . .
    bidPriceCell.Style.Numberformat.Format = RoboReporterConstsAndUtils.NUMBER_FORMAT_ACCOUNTING;