-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Leading zeros are truncated - even if declared as string #493
Comments
Numbers are stored as numbers in PHPExcel unless you use a custom value binder to enforce datatype of string for numeric values with leading zeroes, or you need to set cell values individually using the What you aren't doing is declaring the value as a string.... the This is actually documented behaviour, as described in the Developer Documentation (Setting a number with leading zeroes) |
Ah thanks a lot, I was actually not aware of that. I thought the |
Is there a way to use
By the way: Applied like this, it throws error |
That's right, trying to set cell value on a range of cells will throw an exception... the setCellValue*() methods all work on one, and only one, cell. There is no short-cut to achieve what you want.... And nor can you retrospectively change the datatype of a cell and automatically convert the content to restore something that may have been lost (such as leading zeroes) when the cell value was first set. However, it's pretty straightforward to define a cell binder that will recognise leading zeroes in a cell; and a recent change on the development branch did exactly this |
I see. Thus I updated to the latest version. Works like charm. Thanks! |
I'm fetching some data from a MySQL table and put this into a sheet:
There is one column that only contains numbers with a leading zero (actually no numbers but strings), but the leading zeros are truncated. Even if I explicitly declare values of that column as strings:
I have tried to place the type setting to string before the
fromArray()
statement in order to define the type before filling it with values but it still messes up my values. Do I have to consider something else or is this a bug?The text was updated successfully, but these errors were encountered: