Aug 19, 2009 at 10:28 PM
Edited Aug 19, 2009 at 10:28 PM
I'm new to PHPExcel, but I want to start by saying that this library has been a real life saver!
I'm working on an accounting project where our end-users want MySQL-driven dynamic
data either in CSV, Excel5 or HTML format, and they expect it to look just like their current
spreadsheets. The PHPExcel project has saved me a lot of time, so I thank you.
With that said, I was disappointed at the lack of number formatting options available for
non-Excel formats. I added my own to the source code, in case anyone is interested. It is
for formatting comma-separated numbers with no digits after the decimal place and
negative numbers in parentheses. E.g.:
1000.01 --> 1,000
-1000.01 --> (1,000)
Here is the code I inserted into Classes/PHPExcel/Style/NumberFormat.php:
54: const FORMAT_NUMBER_COMMA_SEPARATED3 = '#,##0_);(#,##0)';
516: else if ($format === self::FORMAT_NUMBER_COMMA_SEPARATED3)
517: return ($value >= 0 ? number_format($value, 0, '.', ',') : "(" . number_format(abs($value), 0, '.', ',') . ")");
I also noticed that the other comma-separated formats are wrong. They both use:
number_format($value, 2, ",", ".")
which sets the '.' as the thousands separator and the ',' as the decimal, which doesn't
match the definition: '#,##0.00'
I'm thinking that I would be willing to help contribute to this, especially because this
is such a nice way to format HTML pages. I would propose a revised
toFormattedString() function that could actually parse any $format and return an
array with an optional color field. Then the writers could interpret the color
information any way that is appropriate.
Thanks again for a really useful library!