andyw27
asked on
Help with sending data to Excel
Hello,
I have a script that runs a query and places the result in excel query. This work fine. I need to take this a step further. When displaying this data directly on to a web page I parse the data so that it only displays part of the information.
Here is the code I have to generate the excel file:
export = mysql_query($query_rs_ssip _ongoing);
$fields = mysql_num_fields($export);
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . "\t";
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data) ;
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/x-msdownload") ;
header("Content-Dispositio n: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
-------------------------- ---------- ---------- --
and here is the code that I use which parses the infromation when displayed on the webpage:
<?php
$text1 = $row_rs_ssip_ongoing['Subj ect'];
$start1 = strpos( $text1, ">" );
$ends1 = strpos( $text1, "#" );
$eng = substr( $text1, $start1+1, ($ends1-$start1-1) );
echo $eng;
?>
What I need to do is merge these two so that the excel output is the same as the information displayed on the website.
Any help appreciated.
I have a script that runs a query and places the result in excel query. This work fine. I need to take this a step further. When displaying this data directly on to a web page I parse the data so that it only displays part of the information.
Here is the code I have to generate the excel file:
export = mysql_query($query_rs_ssip
$fields = mysql_num_fields($export);
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . "\t";
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data)
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/x-msdownload")
header("Content-Dispositio
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
--------------------------
and here is the code that I use which parses the infromation when displayed on the webpage:
<?php
$text1 = $row_rs_ssip_ongoing['Subj
$start1 = strpos( $text1, ">" );
$ends1 = strpos( $text1, "#" );
$eng = substr( $text1, $start1+1, ($ends1-$start1-1) );
echo $eng;
?>
What I need to do is merge these two so that the excel output is the same as the information displayed on the website.
Any help appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The spreadsheet downloads to the users machine.
They differ because the Excel query returns everything whereas the web page breaks down the content.