exporting data into multiple sheets in excel
Posted: Mon Nov 14, 2005 11:31 pm
I have searched for exporting data from mysql into excel but the code i have got puts the data only in one sheet is there
any way so that i can put data into multiple sheets like each table sould go in separate sheet .... Here's the code that i am using
any way so that i can put data into multiple sheets like each table sould go in separate sheet .... Here's the code that i am using
Code: Select all
$con = mysql_connect("localhost" , "root" , "") or die ("Not Fouund" . mysql_error());
mysql_select_db("hic_data") or die ("Not Fouund" . mysql_error());
$select = "SELECT * FROM tbresponsera";
$export = mysql_query($select,$con);
echo mysql_error($con);
$fields = mysql_num_fields($export);
$header = "" ;
$data = "";
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . ",";
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "£";
} else {
$value = $value. "£";
}
$line .= $value;
}
$data .= trim($line)."new line";
}
$data = str_replace("r","",$data);
if ($data == "") {
$data = "n(0) Records Found!n";
}
$title_row = split(",", $header);
foreach($title_row as $title)
$st_data = $st_data."$title \t";
$data_row = split("new line", $data);
foreach($data_row as $row)
{
$st_data = $st_data."\n";
$data_dis = split("£", $row);
foreach($data_dis as $col)
$st_data = $st_data."$col \t";
}
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$st_data";