Convert from currency to Integer in PHPExcel

29 views Asked by At

I'm using PHPExcel(@v1.8.0) to read data in order to save it in my database

I can successfully load and read the file but I've encountered a problem when reading a column styled as "currency" (for the record, data is stored as a number Eg:12154,018037749)

This is how the data looks

As I read it without any modifications data load as: 'Price' => string '$ 12,154.02'

How can I read it as a number? Preferably as an integer (I do not care about cents, so I'm cool with truncating those)

I have tried to set the format to number

$activeSheet = $objPHPExcel->getActiveSheet();
$activeSheet->getStyle('H:H')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);

And then convert it to array:

$sheetData = $activeSheet->toArray(null, true, true, true);

But data is still the same, is there something missing? I have thought about treating it as an string and then convert it but doesn't sounds performant...

0

There are 0 answers