Phpexcel Exporting instances of Excel documents 2003 and 2007

Source: Internet
Author: User
Tags vars

  1. require_once ' common/excel/phpexcel.php ';
  2. require_once ' common/excel/phpexcel/writer/excel2007.php ';
  3. require_once ' common/excel/phpexcel/writer/excel5.php ';
  4. Include_once ' common/excel/phpexcel/iofactory.php ';
  5. $objExcel = new Phpexcel ();
  6. Set properties (This code doesn't matter, the content can be replaced with what you need)
  7. $objExcel->getproperties ()->setcreator ("Andy");
  8. $objExcel->getproperties ()->setlastmodifiedby ("Andy");
  9. $objExcel->getproperties ()->settitle ("Office 2003 XLS Test Document");
  10. $objExcel->getproperties ()->setsubject ("Office 2003 XLS Test Document");
  11. $objExcel->getproperties ()->setdescription ("Test document for Office 2003 XLS, generated using PHP classes.");
  12. $objExcel->getproperties ()->setkeywords ("Office 2003 OPENXML PHP");
  13. $objExcel->getproperties ()->setcategory ("Test result file");
  14. $objExcel->setactivesheetindex (0);
  15. $i = 0;
  16. Table header
  17. $k 1="number";
  18. $k 2="Promotion code";
  19. $k 3="Access source";
  20. $k 4="IP";
  21. $k 5="Access Time";
  22. $objExcel->getactivesheet ()->setcellvalue (' A1 ', "$k 1");
  23. $objExcel->getactivesheet ()->setcellvalue (' B1 ', "$k 2");
  24. $objExcel->getactivesheet ()->setcellvalue (' C1 ', "$k 3");
  25. $objExcel->getactivesheet ()->setcellvalue (' D1 ', "$k 4");
  26. $objExcel->getactivesheet ()->setcellvalue (' E1 ', "$k 5");
  27. Debug ($links _list);
  28. foreach ($links _list as $k = +$v) {
  29. $u 1=$i +2;
  30. / *----------Write content-------------* /
  31. $objExcel->getactivesheet ()->setcellvalue (' a '.   $u 1, $v ["id"]);
  32. $objExcel->getactivesheet ()->setcellvalue (' B ').   $u 1, $v ["num"]);
  33. $objExcel->getactivesheet ()->setcellvalue (' C ').   $u 1, $v ["Referer"]);
  34. $objExcel->getactivesheet ()->setcellvalue (' d '.   $u 1, $v ["IP"]);
  35. $objExcel->getactivesheet ()->setcellvalue (' e ').   $u 1, $v ["Dateline"]);
  36. $i + +;
  37. }
  38. Width of the high column
  39. $objExcel->getactivesheet ()->getcolumndimension (' A ')->setwidth (10);
  40. $objExcel->getactivesheet ()->getcolumndimension (' B ')->setwidth (10);
  41. $objExcel->getactivesheet ()->getcolumndimension (' C ')->setwidth (70);
  42. $objExcel->getactivesheet ()->getcolumndimension (' D ')->setwidth (15);
  43. $objExcel->getactivesheet ()->getcolumndimension (' E ')->setwidth (15);
  44. $objExcel->getactivesheet ()->getheaderfooter ()->setoddheader (' &l&bpersonal cash register  &rprinted on &d ');
  45. $objExcel->getactivesheet ()->getheaderfooter ()->setoddfooter (' &l&b '. $objExcel->getproperties ()->gettitle ().  ' &rpage &p of &n ');
  46. Set page orientation and size
  47. $objExcel->getactivesheet ()->getpagesetup ()->setorientation (phpexcel_worksheet_pagesetup::orientation _portrait);
  48. $objExcel->getactivesheet ()->getpagesetup ()->setpapersize (phpexcel_worksheet_pagesetup::P apersize_a4) ;
  49. $objExcel->setactivesheetindex (0);
  50. $timestamp = time ();
  51. if ($ex = = ') { //export excel2007 document
  52. Header (' Content-type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ');
  53. Header (' content-disposition:attachment;filename= ' links_out '. $timestamp.  '. xlsx ');
  54. Header (' cache-control:max-age=0 ');
  55. $objWriter = Phpexcel_iofactory::createwriter ($objExcel, ' Excel2007 ');
  56. $objWriter->save (' php://output ');
  57. exit;
  58. } else { //export excel2003 document
  59. Header (' Content-type:application/vnd.ms-excel ');
  60. Header (' content-disposition:attachment;filename= ' links_out '. $timestamp.  ' . xls ');
  61. Header (' cache-control:max-age=0 ');
  62. $objWriter = Phpexcel_iofactory::createwriter ($objExcel, ' Excel5 ');
  63. $objWriter->save (' php://output ');
  64. exit;
  65. }

Phpexcel Exporting instances of Excel documents 2003 and 2007

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.