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.
Related
I have some cell on excel file with General format.
The value of this cell is
1,99
10,88
Using phpexcel, When I read the cell i got:
1.99
10.88
How can I get the original value 1,99 ?
I did try
$sheet->getCell("C2")->getValue();
$sheet->getCell("C2")->getFormattedValue()
But both return the
1.99
10.88
PHPExcel cannot possibly know the locale setting that are configured for any users version of MS Excel, and handling of locale-specific formattings (such as decimal commas rather than points) is specific to an instance of MS Excel itself. If I opened that same file in my copy of MS Excel, then I would see a decimal point... i.e. local settings aren't defined in the file, they're purely in the MS Excel GUI.
If you need to format specific to a users locale, then retrieve the raw data using getValue(), and use PHP's Intl NumberFormatter to localise the 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 on a PHP site where I have to export all the users from mysql database.
Everything is working well but when I open the exported csv file, the mobile number and the date are not showing up in proper format i.e mobile number appears as hexadecimal and the date appears as #####.I want to it in a proper data format any help ? thanks in advance
It is actually not that sign, click on it will show you value. CSV just show it as a preview.
You have high expectations about the CSV format. It's nothing but plain text divided into columns, as you can check by yourself if you simply open the resulting file in a text editor (rather than double-clicking it and getting it loaded by the default program). Interpretation of its contents is basically left to the client-side spreadsheet software and you're apparently using the least usable among all: Microsoft Excel.
Excel doesn't prompt for any option when you double-click on a file. It uses default options for everything and most of those defaults are poorly chosen:
File encoding is the computer's default encoding: Win-1252, EUC-JP...
Column separator is the computer's default list separator: , in the US, ; in some European countries...
Dates must be in the computer's default date format: MM/DD/YYYY in the US, DD/MM/YYYY almost everywhere else.
Leading zeroes are discarded.
If you load the file in e.g. LibreOffice Calc you get a dialogue instead where you can ensure that data gets loaded properly (but, still, it's a manual task you need to do every time).
To sum up: CSV is a terrible format if you don't have control on how it's going to be processed (but it's popular because it's so easy to generate).
As about your exact questions:
mobile number appears as hexadecimal
I suspect you mean this:
6.00912E+15
This is not hexadecimal, it's the scientific notation you were taught at school (6.00912 × 1015) as it's normally represented in computers. It's how Excel displays large numbers; because, yes, Excel will insist on handling phones as numbers (which they aren't). If you click on the cell, you'll see the full value in the top bar.
Please note that that phone numbers that start with 0 (e.g. international numbers in 00<country code> format) will not load properly in Excel. It'll drop leading zeroes and changing the cell format to "Text" will not get them back.
the date appears as #####.
And this is how Excel represents that a column is too narrow to show a value. Just drag the little separator between column headers.
<?php
session_start();
$csv_output = '';
$query_result=mysql_query("select * from tablename");
//add your table field name and proceed forther
while($result=mysql_fetch_array($query_result)){
$csv_output.=",".$result['fildname']." ";
}
//$csv_output.="\n";
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=csvfile.csv");
header("Pragma: no-cache");
header("Expires: 0");
print $csv_output;
exit;
?>
i try this hope you can use this thing
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/
I have an excel spreadsheet that contains some formulas to calculate ROI for an upcoming product of a client. Is it possible to convert this into a php script whereby a user would type into some boxes and then submit it working out the same. The excel spreadsheet is here: http://www.solidcamxpress.co.uk/roi.xls
Sure, PHP can do math just like Excel's formulas. However, there is no magic method of converting Excel to a Web page, if that's what you're asking.
#Cameron
There is a software in the market which can convert the spreadsheet to active html/php with ease. You can get the software at the following url:
http://www.spreadsheetconverter.com
Even you can also convert the spreadsheet by yourself as it is simple to convert with scripts. but you can also this software for the conversion =)
You can use PHPExcel to read an existing spreadsheet and extract its data/formulas, but converting those formulas from Excel syntax to PHP is rather non-trivial.
Unless you're doing a generalized Excel->PHP converter, the time/effort required to write such a converter will be far greater than it would take you do analyze the one spreadsheet by hand and code up some PHP stuff to recreate it.