Luis Sardinha
Luis Sardinha

Reputation: 21

Laravel-Excel column formatting replaces digit with 0

Versions

Description

When exporting to an excel spreadsheet, column formatting is generating a rounded number.

Steps to Reproduce

Expected behavior:

Column with following format:

$sheet->setColumnFormat(
       array( 'C' => '0', //NUMBER format 
));

for a number like: 4444444444444444, it should reproduce the exact same number,

Actual behavior:

Instead, it is generating the following: 4444444444444440 It is replacing the last "4" with a "0".

Additional Information

By changing the format to "TEXT" or "General" the same happens and the number represent in scientific notation number: 4.44444E+15

Reference for available column formatting

Upvotes: 1

Views: 2628

Answers (2)

Luis Sardinha
Luis Sardinha

Reputation: 21

Not the ideal solution but it works fine.

$sheet->setCellValueExplicit('C'.$rowCount, $myData);

First I append all the data with the format I want to the row, and then I populate only the cell I need with explicit data using the method setCellValueExplicit. A little "hack", I would say.

Upvotes: 1

user4039065
user4039065

Reputation:

It seems that you are experiencing 15 digit precision. Anything exceeding 15 digits will result in rounding.

Upvotes: 0

Related Questions