Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

number overflow bug #17

Closed
buptlsp opened this issue Jan 23, 2019 · 5 comments
Closed

number overflow bug #17

buptlsp opened this issue Jan 23, 2019 · 5 comments
Labels
question Further information is requested

Comments

@buptlsp
Copy link

buptlsp commented Jan 23, 2019

Hello, I have a question about the format of spreadsheet. I use the package to export a excel, it may look like this:
$exporter = new Spreadsheet([ 'dataProvider' => $dataProvider, 'columns' => [ 'id', 'idCard', ] ]);
The idCard is an 18-digit number。but when I download the excel ,it show like this:
image

I just want it process the idCard as a string, this format is not I want. now the value is 411627200002085000. in fact, the value of idCard here is "411627200002084831". I think this bug is the number have overflowed。i think if I set the number format to text, it may work well. so I change code to this:
$exporter = new Spreadsheet([ 'dataProvider' => $dataProvider, 'columns' => [ 'id', [ 'attribute' => 'idCard', 'contentOptions' => [ 'numberFormat' => [ 'formatCode' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT, ], ], ] ] ]);
the result change to this, it changed the format to text, but it still an Incorrect value.
image

I checked the code, and i think the reason is the number is too big. when we set value to cell ,it has already overflowed. and then ,I set the format to text, the value can't change to the original value, so the text is wrong. the code is in "yii2tech/spreadsheet/src/Spreadsheet.php",
public function renderCell($cell, $content, $style = []) { $sheet = $this->getDocument()->getActiveSheet(); $sheet->setCellValue($cell, $content); $this->applyCellStyle($cell, $style); return $this; }
when we set cellvalue ,the value has already overflowed, and then I can do noting to change the value to original value. I try to use setCellValueExplicit, and it work well.
Could you please change the function setCellValue to setCellValueExplicit, so I can set the value explicit?

@klimov-paul
Copy link
Member

This does not relate to this package. Consider reporting it to phpoffice/phpspreadsheet.

@klimov-paul klimov-paul added the question Further information is requested label Jan 24, 2019
@buptlsp
Copy link
Author

buptlsp commented Jan 25, 2019

are you kidding?

  • first, it is a bug, and you can fix it easily.
  • second, phpoffice/phpspreadsheet give the function setCellValueExplicit, and your package use setCellValue. you think the bug is created by phpoffice/phpspreadsheet? if you use setCellValueExplicit,there is no bug at all.
  • third, if phpoffice have fixed the question as you wanted, the problem is still exist. the fact is, setCellValue speculates the type of value may not the type of the value user wanted. if we set the config after setCellValue, Type conversion still exist. we should pray there is no loss of precision for all type conversions.

any way, I appreciate for the package.

@klimov-paul
Copy link
Member

first, it is a bug

Expanentianal representation of the large data, e.g. 4.11E+17 is absolutely valid. It may be unappropriate for you, but not for everyone.

second, phpoffice/phpspreadsheet give the function setCellValueExplicit, and your package use setCellValue. you think the bug is created by phpoffice/phpspreadsheet? if you use setCellValueExplicit,there is no bug at all.

Usage of the setCellValueExplicit() produces other issues as broken formatting features.
While it can solve your problem - it will create problem for someone else.
If you require usage of setCellValueExplicit() you can create your own custom column class, overriding its renderDataCell() in whatever you like including usage of setCellValueExplicit(). You already have been given everything you neeed.

@buptlsp
Copy link
Author

buptlsp commented Jan 30, 2019

I'm just a user. the best thing is I don't need to discuss with you. the package may sometimes not performance as user think. we put a string in , and out put an number. change or not change, it's up to you.
the second is not a problem.if user set number format, use setCellValueExplicit to avoid the type conversion. if not, use setCellValue.
I have already solve my problem. I can write a column, or I can change it to string by insert blank to force it to an string......, but it's not beautiful. code is poetry. I'm sorry to disturb you.

@sanwv
Copy link

sanwv commented Jun 16, 2020

no matter number 123 or numeric string "123",the cell alway is a number cell. no way force set datatype unless overwrite a cloumn class. a common case need rewrite class is not friendly

+1 provide a configuration for datatype.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants