如何使用EPPlus将电子表格单元格的内容设置为会计格式?

时间:2017-02-07 21:48:53

标签: excel formatting number-formatting epplus accounting

我需要将某些列的内容设置为会计格式。

这次尝试:

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

...只需将“$”和“ - $”作为值。

这次尝试:

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

...给了我一些价值,例如“$ 24.09”和“ - $ 0.91”

用户想要的是美元符号和值之间的空格,以及负值周围的空白,例如“$ 24.09”和“$(0.91)”

我需要为Numberformat.Format属性分配什么字符串?

2 个答案:

答案 0 :(得分:3)

找到Wildpinkler here的答案,即:

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

...以便以下工作:

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

答案 1 :(得分:0)

由于我需要欧元和西班牙语语言环境的货币格式(例如1.000.000,00€)。我必须:

  1. 解压缩我将该格式应用于单元格的一个excel文件。
  2. 转到xl文件夹并打开styles.xml文件
  3. 找到在 numFmts标记
  4. 之间搜索“€”符号的格式

    styles.xml:

    <numFmts count="2">
        <numFmt numFmtId="44" formatCode="_-* #,##0.00\ &quot;€&quot;_-;\-* #,##0.00\ &quot;€&quot;_-;_-* &quot;-&quot;??\ &quot;€&quot;_-;_-@_-"/>
    </numFmts>
    

    因此,您可以使用以下格式:

    sheet.Cells["A1"].Style.Numberformat.Format = @"_-* #,##0.00\ ""€""_-;\-* #,##0.00\ ""€""_-;_-* ""-""??\ ""€""_-;_-@_-";
    
相关问题