0

I use phpOffice library to read data from an Excel file and convert it to a php array, here his the code providing the php array from excel file data:

$spreadsheet= \PhpOffice\PhpSpreadsheet\IOFactory::load('/User/myMac/exampl.xls');

$data = $spreadsheet_fond->getActiveSheet->toArray();
var_dump($data[0][0]); // display the value of first cellule.

OUTPUT:

"/ 221,066,768\ ‚¬ "

What I really want:

"221,066,768"

I've tried trim(preg_match('#[/‚¬\\\\]#', '', $data[0][0])) and I've got the following results:

"221,066,768 ‚" why does the char "‚" was not replaced?

I see that this char "‚" is different than "," ‚,.

UPDATE

using method getCollection() give the real value, but I'm interested in toArray()method.

code:

$data = $spreadsheet_fond->getActiveSheet()->getCellCollection()->get('A1')->getValue();
var_dump($data);

OUTPUT:

221066767.5 // notice that it returns the original value without applying rounding.

MiharbKH
  • 206
  • 2
  • 9

1 Answers1

0

When applying utf8_decode() function on $data[0][0] the output is: 221,066,768\ ??

The following code solve the issue:

$result = trim(preg_match('#[/?\\\\]#', '', utf8_decode($data[0][0])));
var_dump($result);

OUTPUT:

221,066,768

MiharbKH
  • 206
  • 2
  • 9