简体   繁体   English

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

[英]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. 我需要将某些列的内容设置为Accounting格式。

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" ...给了我价值,如“24.09美元”和“ - 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)" 用户想要的是美元符号和值之间的空间,以及负值周围的空白,例如“$ 24.09”和“$(0.91)”

What string do I need to assign the Numberformat.Format property for this to work? 我需要什么字符串来分配Numberformat.Format属性才能工作?

Found the answer from Wildpinkler here , which is: 这里找到Wildpinkler的答案,即:

@"_(""$""* #,##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;

Due to I need the currency format for Euros and a Spanish locale (example 1.000.000,00€). 由于我需要欧元和西班牙语语言环境的货币格式(例如1.000.000,00€)。 I had to: 我不得不:

  1. Unzip one excel file where I had apply that format to a cell. 解压缩一个excel文件,我将该格式应用于单元格。
  2. Go to the xl folder and open the styles.xml file 转到xl文件夹并打开styles.xml文件
  3. Find the format searching for '€' symbol between the numFmts tags 找到在numFmts标签之间搜索“€”符号的格式

styles.xml: styles.xml:

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

Therefore, you can use this format like this: 因此,您可以使用以下格式:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM