Wrong currency formated cells when converting xls(x) to CSV

Topics: Developer Forum, User Forum
Dec 28, 2009 at 10:46 AM


I'm using PHPExcel 1.7.0 to convert excel files to CSV in the following manner:


$phpExcelObjReader = PHPExcel_IOFactory::createReaderForFile($inputFile);
$phpExcelObj = $phpExcelObjReader->load($inputFile);
$phpExcelObjWriter = PHPExcel_IOFactory::createWriter($phpExcelObj, 'CSV');


While this works great, I'm experiencing problems with currency formatted cells. Lets say in a cell the value is "7.67" and its formatted to be shown as "$7.67". The cell value is still 7.67, but when its formatted, phpExcel will save to CSV file "[$$-8]8" (the value is rounded to 8). "$198.5" whould result to "[$$-199]199". Is there a way to make phpExcel get the value without the formatting? I can also easily try different values with different currencies and write a regex to get the real (not rounded) value for this cells. I just don't have any control over the input xls(x) files.

Thank you for your great work on the library!

Dimitar Dinchev

Dec 28, 2009 at 11:10 AM

Found it. In case someone else is looking for this - after initializing the Reader, before loading the actual file, the reader has setter method "setReadDataOnly()", which will remove all formating from cells.