Computing.Net > Forums > Web Development > XL formats of MySQL/PHP export CSV

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

XL formats of MySQL/PHP export CSV

Reply to Message Icon

Name: fem
Date: November 15, 2004 at 14:34:54 Pacific
OS: W2K/Apache2.0.48
CPU/Ram: PHP 4.3.4.4
Comment:

My web application allows user to select certain part of my MySQL table for export and the route I want to offer is either XLS file or CSV.

Exporting and saving works just fine in both formats, but ... Excel does not want to show data correctly: instead of the value "441234567890" in one column it displays "4.41234E+11". The routes that I've already explored are:
1. Adding " ' " in front of the numbers to tell excel to treat them as text -- Excel treats info as text BUT displays the '-symbol and confuses users
2. Putting brackets around the value -- Excel ignores them and treats info as numbers and does the E+11 trick again

Is there a way to pass to excel column formats with the data -- number formats, column width, etc?

Or has someone found a way to tell Excel that values should be treated as text without changing information displayed in Excel?

Thanks for your help,
Oleg
PS ... here is the current code:
<?php
// Here we tell the browser that this is an excel file.
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=SMSRealty-Sales-Leads-".date("Y-m-d").".csv");
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
//Variables to connect to MySQL database
error_reporting (E_ALL);
$user = "user"; //MySQL Username
$password = "password"; // MySQL Username's Password
$dbname= "dbname"; //Database Name
$tablename ="tablename"; // DB Table Name
$server="server"; //MySQL server name

$global_dbh = mysql_connect("localhost", $user, $password); // This establishes the database connection

mysql_select_db($dbname, $global_dbh); // Select what database to use

// You do not need to change the function
echo "Col1,Col2,Col3,Col4,Col5\n";
$query = mysql_query("SELECT col1, col2, col3, col4, col5, col6 FROM tablename WHERE col7='$variable' AND col8='Y' AND col8 BETWEEN '$startingtime' AND '$endtime'");
while($row = mysql_fetch_array($query)){
echo "$row[col1],$row[col2],$row[col3],$row[col4],$row[col5],$row[col6]\n";
}
?>



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: XL formats of MySQL/PHP export CSV

Php/mySql/Phorum problems www.computing.net/answers/webdevel/phpmysqlphorum-problems/932.html

PHP Form saving to mySQL www.computing.net/answers/webdevel/php-form-saving-to-mysql/615.html

PHP/mySQL .. XML ... Javascript. - www.computing.net/answers/webdevel/phpmysql-xml-javascript-/2157.html