PHPExcel currency get cell value returns as boolean false

1.7k views Asked by At

When importing a .csv file a cell with a currency value e.g. £102.30 is returned as bool(false) when using getCellValue.

$objReader = \PHPExcel_IOFactory::createReader('CSV');
$objReader->setReadDataOnly(true);
$loadedSpreadsheet = $objReader->load($spreadsheet);
$activeSheet = $loadedSpreadsheet->getActiveSheet();

var_dump($activeSheet->getCell('Q13')->getValue()); // bool(false)

It's definitely the correct cell, as columns either side work fine.

I've tried setting the encoding to utf-8 but that hasn't worked either

Row 13:

000001,Mags,Red,0,65,720mm x 1080mm,0,0,0,0,0,0,0,0,,1,£3.22,Mag,,,,,,,,,
1

There are 1 answers

0
Mark Baker On BEST ANSWER

So the strings aren't quoted in the file at all, strictly that's not a valid CSV; but I'm guessing that PHPExcel can't handle the undefined charset... the default is UTF-8, but if this isn't a UTF-8 file, then you need to let PHPExcel know what charset is being used:

$objReader->setInputEncoding('ISO-8859-1');

(or whatever charset the file is using) so that it can know how to convert it to UTF-8

PS

$objReader->setReadDataOnly(true);

is redundant, because a CSV file can't contain anything but data only