You are here: Excel export problem in IE « All PHP « IT news, forums, messages
Excel export problem in IE

Posted by mukherjeesubrato on 05/31/06 15:49

Hi,
I have this script to export mysql data to excel. I have tried
everything but I am not able to get this script to work for IE. The
script downloads the data using Mozilla or Netscape but it fails and
says

Internet Explorer cannot download export.php from "IP Address" (this is

the IP on which the file resides). Internet Explorer was not able to
open this Internet site. The requested site is either unavailable or
cannot be found. Please try again later.


If I remove the header("Content-type: application/vnd.ms-excel;
name='excel'"); then it outputs the database values on the page even
using IE . Not sure what is wrong with the script.


<?php
header("Content-type: application/vnd.ms-excel; name='excel'");
header("Content-Disposition: filename=export.xls");
header("Pragma: no-cache");
header("Expires: 0");


require_once("${HTTP_SERVER_VARS['DOCUMENT_ROOT']}/conf/config.ph");



$query = "Select * from table";
$result = mysql_query($query) or die (mysql_error());
$fields=mysql_num_fields($result);
for ($i=0;i<$fields;$++i)
{
$header .= mysql_field_name($result,$i) . "\t";
}
while($row = mysql_fetch_row($result))
{
$line = '';
$count=0;
foreach($row as $value)
{
if ($count ==15)
{
if ($value == 1)
{ $line .= "Yes" . "\t";}
else
{ $line .="No" . "\t"; }
}
else
{
if((!isset($value) OR ($value==""))
{
$value = "\t";
}
else
{
$value = str_replace('"', '""', $value);
$value = '"' . stripslashes($value) . '"'
.. "\t";
}
$line .= $value;
}
$count ++;
}
$data . =trim($line) . "\n";
}
$data = str_replace("\r", " ", $data);
if ($data=="")
{
$data = "\n No records found\n";


}
echo "$header\n$data\n";
mysql_free_result($result);
?>


This is the whole script. Not sure if the script is wrong somewhere or
what.
Any help is appreciated
Thanks
Subrato

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация