Re: Excel export problem



Hmm... not sure why it wouldn't work for you before.

I have tested out using just the first 2 header statements on a server
running Linux, one running BSD, and one running Win2k. The Win2k is a
dev server I use at home and is running a small intranet off of an IP
(no dns info added).

The other 2 are run off of work servers using a dns entry like
"intranet.ourdomain.com".

Sorry I couldn't help out more. I'm going to see if the "inline" info
changes anything on my end.

Peace,
D.


subrato wrote:
header("Cache-Control: no-stor,no-cache,must-revalidate");
header("Cache-Control: post-check=0,pre-check=0", false);
header("Cache-control: private");
header("Content-Type: application/force-download");
header("Content-Disposition: inline; attachment;
filename=cimarron.xls");
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");

The addition of inline word for Content-Disposition finally made it
work!!
Thanks guys

SM

DonO wrote:
I use...

header("Content-Type: application/vnd.ms-excel; name='excel'");
header("Content-disposition: attachment; filename="
.date("Y-m-d").".xls");

and it works, but I have to either save the file and open it later in
excel, or excel has to be already open for it to open from the link.

I did notice you had...

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

(no "p" at the end of config.ph)

Not sure if that's causing you a problem, or if it was just a typo in
your submission. Let me know if that doesn't work.
D.

subrato wrote:
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

.



Relevant Pages

  • Re: workbooks.open function fails to open an existing excel file when used in ASP, but works in VB.
    ... Just reading the script there doesn't seem to be anything wrong with it, ... excel is definitely not recommended as a server side application. ...
    (microsoft.public.excel.programming)
  • PublishObjects lockup
    ... HOW CAN I MODIFY THIS SCRIPT TO PREVENT LOCKUP IN THE CASE OF FAILURE? ... Excel when the destination server for PublishObjects is not available. ...
    (microsoft.public.excel.programming)
  • Re: Excel export problem
    ... excel, or excel has to be already open for it to open from the link. ... I have this script to export mysql data to excel. ... Internet Explorer cannot download export.php from "IP Address" (this is ... open this Internet site. ...
    (php.general)
  • How to out results in a web Page
    ... I was working on a script which pull the data from a server, ... some results and export it to EXCEL. ...
    (comp.lang.tcl)
  • Re: Excel export problem
    ... excel, or excel has to be already open for it to open from the link. ... I have this script to export mysql data to excel. ... Internet Explorer cannot download export.php from "IP Address" (this is ... open this Internet site. ...
    (php.general)