CREATE TABLE' person ' (' Number`int( One)DEFAULT NULL, ' name 'varchar(255)DEFAULT NULL, ' birthday ' dateDEFAULT NULL) ENGINE=MyISAMDEFAULTCHARSET=UTF8;
INSERT into the person values (1, ' Xiaofei ', ' 20001111 ');
INSERT into the person values (2, ' Xiaopi ', ' 20111111 ');
<?PHP/** * @category phpexcel * @package phpexcel * @copyright Copyright (c) 2006-2015 Phpexcel (Http://www.codeplex. Com/phpexcel) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version # #VERSION # #, # #DAT e##*//** Error Reporting*/error_reporting(E_all);Ini_set(' Display_errors ',TRUE);Ini_set(' Display_startup_errors ',TRUE);d Ate_default_timezone_set (' Europe/london ');if(Php_sapi = = ' CLI ') die(' This example should-only is run from a Web Browser ');/** Include Phpexcel*/require_once dirname(__file__) . ‘/.. /common/phpexcel.php ';//Create New Phpexcel Object$objPHPExcel=NewPhpexcel ();//Set Document Properties$objPHPExcel->getproperties ()->setcreator ("Maarten Balliauw") ->setlastmodifiedby ("Maarten Balliauw") ->settitle (Office "XLSX Test Document") ->setsubject (Office "XLSX Test Document") ->setdescription ("Test document for Office" XLSX, generated using PHP classes.)) ->setkeywords ("Office openxml PHP") ->setcategory ("Test result file");//ADD Some data$objPHPExcel->setactivesheetindex (0) ->setcellvalue (' A1 ', ' ID ') ->setcellvalue (' B1 ', ' Name! ')) ->setcellvalue (' C1 ', ' birthday '));//add MySQL data, UTF-8$con=mysql_connect("localhost", "root", "root");if(!$con){ die(' Could not connect: '.Mysql_error());}mysql_select_db("Test",$con);$result=mysql_query("SELECT * FROM Person");$i= 1; while($row=Mysql_fetch_array($result)){ $objPHPExcel->setactivesheetindex (0) ->setcellvalue (' A '.$i,$row[' Number ']) ->setcellvalue (' B ').$i,$row[' Name ']) ->setcellvalue (' C ').$i,$row[' Birthday ']); $i++;}Mysql_close($con);//Rename Worksheet$objPHPExcel->getactivesheet ()->settitle (' Example ');//Set Active sheet Index to the first sheet, so Excel opens this as the first sheet$objPHPExcel->setactivesheetindex (0);//Redirect output to a client ' s Web browser (EXCEL5)Header(' Content-type:application/vnd.ms-excel ');Header(' content-disposition:attachment;filename= ' 01simple.xls "');Header(' Cache-control:max-age=0 ');//If you ' re serving to IE 9 and then the following is neededHeader(' cache-control:max-age=1 ');//If you ' re serving to IE over SSL and then the following is neededHeader(' Expires:mon, Jul 1997 05:00:00 GMT ');//Date in the pastHeader(' last-modified: '.gmdate(' d, D M Y h:i:s '). ' GMT ');//Always modifiedHeader(' Cache-control:cache, Must-revalidate ');//http/1.1Header(' Pragma:public ');//http/1.0$objWriter= Phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel5 ');$objWriter->save (' Php://output ');Exit;
"Phpexcel instance" PHP Export Excel instance