Php+mysql How to convert a datasheet to Excel output

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags activate application content datasheet file how to information mysql

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 ><h3> Serial Number </h3></td>
<TD ><h3> Content </h3></td>
<TD ><h3> Content </h3></td> </tr></table>

?

$exapp = new COM ("Excel.Application") or Die ("Did not connectwww.jzread.com 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 "" The "" "the name of the
///Fill cell
$maxi =20
$m =1
for ($i =1; $i < $maxi; $i + +) {
 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);
Filed
$file _name= "D:/test.xls"; Path
if (file_exists ($file _name)) {@unlink ($file _name) or Die ("www.jzread.com 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 header ("content-disposition:filename= $xlsname. xls");
The second complex but relatively high, features more. The third type of
is to output the data in CVS format.

Related Article

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.