0

I have cell content looks like "$ 1440" or "€ 970" But on formula-field (after select cell) value looks like simple number "1440" or "970". How can I get currency sign ($ or €) by using PhpSpreadsheet?

I tried code

$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
$reader->setReadDataOnly(TRUE);
$spreadsheet = $reader->load('some.xlsx');
$worksheet = $spreadsheet->getActiveSheet();

$a = $worksheet->getStyle(10, 3)->getNumberFormat()->getFormatCode();
$b = $worksheet->getCellByColumnAndRow(10, 3)->getValue();
$c = $worksheet->getCellByColumnAndRow(10, 3)->getFormattedValue();

Got: a - 'General' (string) b - 1440 (integer) c -'1440' (string)

Why is format "General" if it "Finance" actually?

Flam
  • 21
  • 2

1 Answers1

0

You use $reader->setReadDataOnly(TRUE);.

That meant ignore formetting.

Set it to $reader->setReadDataOnly(FALSE);

  • Thanks, now I got: a - 'General' (string), b - 1440 (integer), c - '€ 1440' (string).  It is ok, and I can get euro sign from formatted string, but why formatCode is 'General' if it was set as 'Finance with currency' on MSExcel? Is it normal? – Flam Jul 02 '19 at 19:35
  • There is no >Finace< type in phpspreedsheet. You can use `FORMAT_CURRENCY_EUR`. See [documentation numberformat](https://phpspreadsheet.readthedocs.io/en/latest/topics/recipes/#number-formats), [api numberformat](https://phpoffice.github.io/PhpSpreadsheet/master/PhpOffice/PhpSpreadsheet/Style/NumberFormat.html), [api Cell Datatype](https://phpoffice.github.io/PhpSpreadsheet/master/PhpOffice/PhpSpreadsheet/Cell/DataType.html) and [documentation datatypes](https://phpspreadsheet.readthedocs.io/en/latest/topics/accessing-cells/#excel-datatypes) for more information. – Collie-IT Anne K. Frey Jul 03 '19 at 05:15