Home » excel » php – numbers issue after export mysql data to CSV

php – numbers issue after export mysql data to CSV

Posted by: admin April 23, 2020 Leave a comment

Questions:

when i get data from database and export it as a csv file i have following issues :

  • the leading zero of the numbers dosnt show
  • big numbers shows like this -> 1E+12

how to force MS Excel to show all of my data as string by PHP

How to&Answers:

You can use double quotes contain the numbers, like this:

if(is_numeric($column)) $column = '"'.$number.'"';

Answer:

This isn’t a MySQL issue, it’s an Excel thing.

This… might help: http://answers.microsoft.com/en-us/office/forum/office_2007-excel/disabling-scientific-notation/943b8103-8c50-451d-8037-c697422e2307

But this question is more MS Office related than programming.

(or as comments suggested, use a file format that carries display formatting info, such as .xls)

Answer:

I format it as a string by concatenate it with spaces at its start and end.

CONCAT(" ", database_number, " ") AS "Number For Excel".

Answer:

You can use number_formate() function to convert …

View link

Function : number_format()
Syntax : number_format ( float $number , int $decimals = 0 , string $dec_point = ‘.’ , string $thousands_sep = ‘,’ )
Example to convert 6.90743E+11 to number use below code

number_format(6.90743E+11,0,”,”) // outputs 690743000000