- require_once ' common/excel/phpexcel.php ';
- require_once ' common/excel/phpexcel/writer/excel2007.php ';
- require_once ' common/excel/phpexcel/writer/excel5.php ';
- Include_once ' common/excel/phpexcel/iofactory.php ';
- $objExcel = new Phpexcel ();
- Set properties (This code doesn't matter, the content can be replaced with what you need)
- $objExcel->getproperties ()->setcreator ("Andy");
- $objExcel->getproperties ()->setlastmodifiedby ("Andy");
- $objExcel->getproperties ()->settitle ("Office 2003 XLS Test Document");
- $objExcel->getproperties ()->setsubject ("Office 2003 XLS Test Document");
- $objExcel->getproperties ()->setdescription ("Test document for Office 2003 XLS, generated using PHP classes.");
- $objExcel->getproperties ()->setkeywords ("Office 2003 OPENXML PHP");
- $objExcel->getproperties ()->setcategory ("Test result file");
- $objExcel->setactivesheetindex (0);
- $i = 0;
- Table header
- $k 1="number";
- $k 2="Promotion code";
- $k 3="Access source";
- $k 4="IP";
- $k 5="Access Time";
- $objExcel->getactivesheet ()->setcellvalue (' A1 ', "$k 1");
- $objExcel->getactivesheet ()->setcellvalue (' B1 ', "$k 2");
- $objExcel->getactivesheet ()->setcellvalue (' C1 ', "$k 3");
- $objExcel->getactivesheet ()->setcellvalue (' D1 ', "$k 4");
- $objExcel->getactivesheet ()->setcellvalue (' E1 ', "$k 5");
- Debug ($links _list);
- foreach ($links _list as $k = +$v) {
- $u 1=$i +2;
- / *----------Write content-------------* /
- $objExcel->getactivesheet ()->setcellvalue (' a '. $u 1, $v ["id"]);
- $objExcel->getactivesheet ()->setcellvalue (' B '). $u 1, $v ["num"]);
- $objExcel->getactivesheet ()->setcellvalue (' C '). $u 1, $v ["Referer"]);
- $objExcel->getactivesheet ()->setcellvalue (' d '. $u 1, $v ["IP"]);
- $objExcel->getactivesheet ()->setcellvalue (' e '). $u 1, $v ["Dateline"]);
- $i + +;
- }
- Width of the high column
- $objExcel->getactivesheet ()->getcolumndimension (' A ')->setwidth (10);
- $objExcel->getactivesheet ()->getcolumndimension (' B ')->setwidth (10);
- $objExcel->getactivesheet ()->getcolumndimension (' C ')->setwidth (70);
- $objExcel->getactivesheet ()->getcolumndimension (' D ')->setwidth (15);
- $objExcel->getactivesheet ()->getcolumndimension (' E ')->setwidth (15);
- $objExcel->getactivesheet ()->getheaderfooter ()->setoddheader (' &l&bpersonal cash register &rprinted on &d ');
- $objExcel->getactivesheet ()->getheaderfooter ()->setoddfooter (' &l&b '. $objExcel->getproperties ()->gettitle (). ' &rpage &p of &n ');
- Set page orientation and size
- $objExcel->getactivesheet ()->getpagesetup ()->setorientation (phpexcel_worksheet_pagesetup::orientation _portrait);
- $objExcel->getactivesheet ()->getpagesetup ()->setpapersize (phpexcel_worksheet_pagesetup::P apersize_a4) ;
- $objExcel->setactivesheetindex (0);
- $timestamp = time ();
- if ($ex = = ') { //export excel2007 document
- Header (' Content-type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ');
- Header (' content-disposition:attachment;filename= ' links_out '. $timestamp. '. xlsx ');
- Header (' cache-control:max-age=0 ');
- $objWriter = Phpexcel_iofactory::createwriter ($objExcel, ' Excel2007 ');
- $objWriter->save (' php://output ');
- exit;
- } else { //export excel2003 document
- Header (' Content-type:application/vnd.ms-excel ');
- Header (' content-disposition:attachment;filename= ' links_out '. $timestamp. ' . xls ');
- Header (' cache-control:max-age=0 ');
- $objWriter = Phpexcel_iofactory::createwriter ($objExcel, ' Excel5 ');
- $objWriter->save (' php://output ');
- exit;
- }
Phpexcel Exporting instances of Excel documents 2003 and 2007