카테고리 없음

php spreadsheet output 엑셀 다운시 숫자가 올림처리 되는 현상 해결

Sein_ 2024. 4. 18. 11:02
728x90

1. String Convert 해봄 -> 실패

2. 임의의 String 을 붙여서 출력 -> 성공 (하지만 불필요한 데이터 추가됨)

3. 셀 데이터 타입을 String 으로 변경하여 출력 -> 성공

 

 

Quite an old question but I had this problem as well, PHPSpreadSheet was changing big numbers like 1606778294323857 into 1606778294323860. If you just need to have those values as is and do not need to have it "formatted" (type) as number, this helped me.

Solution was to set the type to String explicitly:

 

$sheet->getCell('A1')->setValue(1606778294323857)->setDataType(DataType::TYPE_STRING);

 

아래와 같이 사용

$activeSheet->getCell('A' . $rowNum)->SetValue($compare['id'])->setDataType(DataType::TYPE_STRING);

 

 

REF

https://stackoverflow.com/questions/58075303/phpspreadsheet-rounding-off-the-accountnumbers-and-removing-0-from-starting

 

Phpspreadsheet rounding off the accountnumbers and removing 0 from starting

I am working on phpspreadsheet where i am downloading the users account details, but phpspreadsheet is rounding off the account numbers and also removing the 0 from starting. Example: Original=>

stackoverflow.com