Hello
I'am trying to read CSV file. The reader gives me everytime a float a return value back. Why is only float import allowed?
I have tried the https://phpspreadsheet.readthedocs.io/en/develop/topics/reading-files/#a-brief-word-about-the-advanced-value-binder but here i have just the option to set numeric or string. But i want just int.
https://github.com/PHPOffice/PhpSpreadsheet/blob/master/src/PhpSpreadsheet/Cell/Cell.php#L219
IIRC spreadsheets have no int, only floats displayed as integers.
I think you will have to cast manually.
This looks like a support question. Please ask your support questions on StackOverflow, or Gitter.
Thank you for your contributions.
It's a desgin pattern fail.
Yup, but that's Microsoft's failure, not PhpOffice'. ^^
Yup, but that's Microsoft's failure, not PhpOffice'. ^^
Cell::setValueExplicit is also used by Csv and many other readers which have nothing to do with Microsoft.
This is a HUGE source of implicit bugs. I've just spent an hour figuring out why value 42 in my csv file is not an integer. is_integer() returned false despite I clearly saw 42 without quotes in xdebug console. I'd rather return just a raw string obtained from the source file.
MS Excel doesn't differentiate between integer and float, it just has a type number; so internally PHPSpreadsheet uses a float for numbers, because a number can be either, but casting a float to an int would cause a lot more problems.
Files like CSV where there is no explicit datatyping use the default value binder, which attempts to map datatypes to the most appropriate Excel type, so a value like 42 is treated as a number and cast to float.
If you would rather that all input from a csv file was treated as string, then the latest master includes a StringValueBinder that explicitly treats all input values as string.
Note also that PHP will display floats that appear to be integers but aren't if the decimal digits are zero... it still isn't an integer: https://3v4l.org/NMBRr