PHPExcel会计格式 [英] PHPExcel Accounting Formats
问题描述
我正在使用PHPExcel,并且正在尝试使用Excel的内置会计"格式来设置单元格的格式.我知道格式代码:
I'm working with PHPExcel and I'm trying to format a cell using Excel's built-in "Accounting" format. I'm aware of the Format Code:
PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE
但这只是格式化为两位小数,并在数字前面加了一个$.我要寻找的结果是右对齐的单元格,左侧是$. $ 0值应列为-",负值应为$(1.11)
But this simply formats to two decimal places and adds a $ in front of the number. The result I'm looking for is the right aligned cell with the $ on the left. $0 values should be listed as "-" and negative values should be $ (1.11)
据我所知文档中没有其他货币格式(尽管我可能已经错过了,但该文档太可怕了).我看错地方了吗?可以使用常规的单元格格式来实现这一点,还是Excel在记帐方面做独特的事情?
As far as I can tell there are no other currency formats in the documentation (though I may have missed it, this documentation is horrendous). Am I looking in the wrong place? Can this be achieved with regular cell formatting or is Excel doing something unique for Accounting?
推荐答案
我使用PHPExcel对现有电子表格中的格式代码进行了反向工程,并获得了以下信息:
I reverse engineered the format code from an existing spreadsheet using PHPExcel and got this:
_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)
这是当您选择会计"格式...或单击Excel 2007中的"$"工具栏按钮时Excel放置在单元格上的代码.
This is the code Excel places on the cell when you select the "Accounting" format... or click that "$" toolbar button in Excel 2007.
如果您不需要货币符号:
If you didn't need currency symbol :
->setFormatCode("_(* #,##0.00_);_(* \(#,##0.00\);_(* \"-\"??_);_(@_)");
这篇关于PHPExcel会计格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!