I have received a report as an CSV file. It contains the contact names and contact numbers.
When i try to open the file in Excel, it displays the contact number like "912224308876". But, if i try to open that file in notepad or try to read in PHP then i get that contact number in different format i.e. "9.12224E+11".
Does any one has idea to solve this issue?
Thanks in advance.
The problem is that Excel treats long numbers as floating point and converts them to scientific notation, often in a lossy way. As described below, the best options are either to use a TXT extension instead of CSV and use the import wizard (which allows you to specify column types), or to use a formula instead of a number to fake out Excel.
http://social.msdn.microsoft.com/Forums/en-US/exceldev/thread/64c1ee52-eb53-4202-bb27-d9b08d3bd60a/
Related
When reading an Excel file with PHPExcel Reader, long numbers are printed out in scientific format, so 0.0000000123 becomes 1.23E-08.
The documentation says I can avoid this with Advanced Value Binder, but unfortunately this only works with CSV files.
Also setReadDataOnly() does not help.
It also happens if the cell is formatted with long floating numbers so it is displayed as 0.0000000123 in Excel.
There are some topics here for writing, but not for reading.
Question: How do I fetch the number w/o scientific format?
Just came across the idea, that PHP is responsible for echo scientific notation, so I have tried number_format($var, 8); and it worked.
So it's not PHPExcel. I have to echo using number_format.
which contains contact numbers in "9.77985E+12" format. I have to save the actual contact numbers in mysql database in this format "9779849561769". Excel automatically converts the number into "9.77985E+12" format. I need to convert "9.77985E+12" format into "9779849561769" format using PHP. How can I do this?
I used a third party library but it saves in "9.77985E+12" format.
The data 9.77985E+12 is a float. It's a not usually a good idea to convert from a floated value to a full value when you need the exact value as you can lose precision from the initial.
You should be able to set the formatting of the cells in excel to 'text' instead of 'integer', which will fix the problem in excel.
Otherwise try this in your PHP to convert it
echo number_format($float,10,'.','');
if this problems comes for a javascript user when exporting a csv in
excel format, can use below method. that will solve the problem.
let mobile = +941231234123
let mobileForCsv = mobile + '\t';
console.log(mobileForCsv) // +941231234123
The problem occured when i saved numbers in CSV format from microsoft excel, it loses some degree of precision. This happened while saving the file from my computer only. I tried saving the file from another computer, it worked. I don't know what happened to my excel software.
i am working in mysql table to generate CSV file conversion using php.
Credit card numbers are shown in mysql database like this 44445959636345. When i converting mysql table to csv file it doesn't show proper credit card number shown just like this 4.4446E+13
My sql query is $this->dbutil->csv_from_result($query);
CSV files changes all the card numbers! For example if your card
44445959636345
Instead of showing up as shown above... CSV changes it and makes it show up as:
4.4446E+13
How can i solve this issue please guide me.
If you want to view the csv file in excel you can put a single quote in front of the number that way it will be displayed as text.
WARNING this means that you need to remove that quote when importing a csv file like this into your DB. This can be done with php or sql substring functions.
so instead of 44445959636345 output '44445959636345 to your csv file.
The problem is: the function refers to the credit number as an integer. What you have to do is to make it refer to it as a text.
i created an application that takes the excell output of a table.There are long numbers in table cell.When i took the output the cells that have long numbers are seen like that 1234+E34.how can i fix that?Thanks for advance...
So you're not actually writing an Excel file: It looks as though you're writing an HTML file but sending headers to the browser telling it that it's an xls file...
Excel can then identify that HTML, and parse it into a structure that it can display.
You have a couple of alternatives.
The first is to create a genuine xls file rather than trying to con the browser and Excel. The Second option: instead of writing the value as
12345678901234567890
write it as
="12345678901234567890"
This will display in excel as "12345678901234567890" (with Quotes)
To avoid this, Use intval(12345678901234567890) in php, This forces Excel to treat this number as an integer
I am generating a simple csv file using php. The file contains some user's personal data.
When I open the generated file in office, the addresses are not displayed in full height. I have to double click on the cell for the address to be shown fully (in full width and height) otherwise I can only see the first word/number of the address.
Also, I have date of births displayed as ######, I have to expand the whole column to see them fully.
This doesn't happen in open office.
Is there any way to force MS Office to show all fields in full? Because otherwise it'll be to confusing for the people who will use (Hey where are all the details!:)
Thanks :)
I don't think you can "format" your sheets with CSV. You will have to produce some other file format that Excel understands. I would suggest XML which is really easy to generate.
Just make a sample sheet with the data you want, save it as XML and you'll see how your file should be generated.
Or you could use some ready-made PHP solution for writing excel files if you can't be bothered with analysing the XML file.
you could try the auto-size columns feature.
This is a UI issue with how Excel works, you can't force Excel or anything else how they handle it.
The quickest work around is to perhaps create an XLS file that runs a macro to retrieve the CVS file and format the cells as needed, but there's nothing you can do inside the CSV to affect what Excel is displaying.