Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

export to excel data 2

Status
Not open for further replies.

OldSmelly

Programmer
Nov 22, 2001
70
NL
I'm on fire now :D

I have searched this form and come up whith this litle script to create a excel-sheet. But what it does it actualy creates a file with the jpg in it from my header ?? very weird I think Anyone got a idea


function create_excel_file($querystring)
{
$file="test.xls";
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment;filename=".$file );
header('Pragma: no-cache');
header('Expires: 0');
$result_excel = mysql_query($querystring);
if($result_excel)
{
$columns=mysql_num_fields($result_excel);
for ($i = 0; $i < mysql_num_fields($result_excel); $i++)
{
print "\"".mysql_field_name($result_excel,$i)."\",";
}
echo "\n";
While ($myrow = mysql_fetch_array($result_excel))
{
for ($i = 0; $i < ($columns); $i++)
{
echo "\"".$myrow[$i]."\",";
}
echo "\n";
}
}
else
{
echo "No results";
}
}
 
No workaround ready at the moment :D

I'm uploading about 2 milion records into my mysql database at the moment...... :)
 
Excel clearly thinks that is a reference of some sort and is trying to look for it, but gets confused. Best way to avoid things like that is to precede all your fields with a single quote ('). That is not printed in the field itself but it will tell Excel that a field is a regular text field and nothing else.
 
Thanks for the input

Im gonna try this later this day, now I'm, off to work...

Hans
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top