How PHP MySQL converts a datasheet to Excel output

Source: Internet
Author: User
Tags mysql tutorial php mysql php tutorial

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.