PHP Tutorial MySQL Tutorial How to convert a datasheet to Excel output
$xlsname = "pour out information";
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:filename= $xlsname. xls");
?>
<table>
<tr>
<TD ><TD ><TD >
?
$exapp = new COM ("Excel.Application") or Die ("Did not connectwww.111cn.net prompts you");
$WKB = $exapp->workbooks->add ();
$ex->application->visible = 1;
$sheets = $wkb->worksheets (1) //Select first sheet
$sheets->activate; //Activate
$sheets->name= "The" "" The "" "," "" The name of the
///Fill cell
$maxi =20
$m =1
for ($i =1; $i < $maxi; $i + +) {
& Nbsp;for ($n =1 $n <5; $n + +) {
$cell = $sheets->cells ($i, $n); #Select the cell (Row Column number)
$cell->activate;
$cell->value = $m;
$m + +;
}
}
$ch = $sheets->chartobjects->add (50, 40, 400, 100); #作图
$chartje = $ch->chart;
$chartje->activate;
$chartje->charttype=63;
$selected = $sheets->range ("E1:e$maxi");
$chartje->setsourcedata ($selected);
Save
$file _name= "D:/test.xls"; Path
if (file_exists ($file _name)) {@unlink ($file _name) or Die ("Www.111cn.net prompts you: File already exists and cannot be deleted!");}
$WKB->saveas ($file _name); Save
$exapp->quit ();
Unset ($exapp);
echo "Build success!";
Method Three
$a = "account number, mailbox, sex, baby date of birth, province, real name, postcode, mobile phone, address RN";
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:filename=". $Filename);
$SQL = "SELECT * from Oy_use";
$Result = mysql_query ($SQL) or Die (Mysql_error ());
while ($rs = Mysql_fetch_array ($Result)) {
if (Get_days ($rs [' m_time ']) <= $Table) {
$a. = $rs [' user_name ']. $rs [' User_mail ']. ",". ($rs [' User_baby_sex ']? Male ': ' Woman '). ",". $rs [' User_baby_birth ']. ",";
$a. = "". $rs [' Sheng ']. ",". $rs [' User_rname ']. ",". $rs [' User_zip ']. $rs [' User_hand ']. ",". $rs [' user_address ']. "RN";
// }
}
echo $a;
/*
The first method is the simplest to header ("Content-disposition:filename= $xlsname. xls"); Output on the line.
The second complex but relatively high, the function is more.
The third way is to output the data in CVS format.