Currency Support

Topics: User Forum
Apr 5, 2009 at 7:49 AM
Edited Apr 5, 2009 at 7:50 AM
Currency support is limited to USD and Euro would it be possible to support GBP (£) as well?

Thanks very much
Developer
Apr 5, 2009 at 8:34 AM
You can define your own custom number format code. Example:

$objWorksheet->getCell('A1')->setValue(1.89);
$objWorksheet->getStyle('A1')->getNumberFormat()->setFormatCode('"£"#,##0.00_-');

Just remember to save your script as UTF-8.

If you are unsure what the format code should look like you can in most cases just create a template xlsx file in MS Office Excel, then use PHPExcel to read of the format code. Alternatively, take your template xlsx file, change file extension to zip, unzip it, locate file xl/styles.xml, and look for the formatCode. Example of an entry for a number format code:

<numFmt numFmtId="164" formatCode="&quot;£&quot;#,##0.00_-"/>

Apr 5, 2009 at 9:25 AM
Thanks very much
Apr 5, 2009 at 9:46 AM
Coding is set to UTF-8 but I now get the following error
"EXcel found unreadable content in ....xlsx

The log shows "<removedPart>Removed Part: /xl/styles.xml part with XML error. (Styles) Illegal xml character. Line 5, column 44.</removedPart>" which is the £ sign
Developer
Apr 5, 2009 at 10:08 AM
Hmm... With that error I can hardly believe it is properly encoded in UTF-8.

Here is what it should look like in Notepad++

Apr 5, 2009 at 11:18 AM
Ooops Looked at it again and you are quiet right I was been thrown by the XML in the file! Now working fine

Thanks again

Adam