Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

XL formats of MySQL/PHP export CSV

Original Message
Name: fem
Date: November 15, 2004 at 14:34:54 Pacific
Subject: XL formats of MySQL/PHP export CSV
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";
}
?>


Report Offensive Message For Removal





Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: XL formats of MySQL/PHP export CSV

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




My PC has been hijacked!

Lexmark 2600 Printer Issues

btk1w1 infected start here post

Unwanted message remians on screen

Slow boot time


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC