PHP Export Excel

Source: Internet
Author: User

Feel the technical mastery of some too miscellaneous, a while to tinker with Java, a while to tinker PHP, while still engaged in. NET, maybe this just are life.

Before colleagues to a county legal committee do a set of stability information platform, the database is packaged MySQL, now customers want to export the data into a province of a set of platforms, preferably exported to Excel, online search for information is simply realized.

1. Download the Phpexcel class library, http://phpexcel.codeplex.com/, into the local lib/phpexcel

2. Follow the example implementation to export the Excel code as follows:

  include_once'./lib/phpexcel/phpexcel.class.php '; include_once'./lib/phpexcel/phpexcel/iofactory.php '; $inputFileName= './dispute.xls '; $excel= Phpexcel_iofactory::load ($inputFileName); $excel->getproperties ()->setcreator ("Sxg")     ->setlastmodifiedby ("Sxg")     ->settitle ("Contradictory dispute export data")     ->setsubject ("Contradictory dispute export data")     ->setdescription ("Dispute contradictory dispute export data"); $excel->setactivesheetindex (0); $objActSheet=$excel-Getactivesheet (); $SQL= "SELECT * from Dispute order by DispID limit 0,2"; $rst= Db::execute ($SQL, 20011, ' dispute ', ' admin ', ', ', ' query '); $arr=Split("\1",$rst); $row=2; foreach($arr  as $rs){    $col=0; $VALARR=Split("\2",$rs); foreach($VALARR  as $val) {     $objActSheet->setcellvaluebycolumnandrow ($col,$row,$val); $col++; }    $row++; }  $objWriter= Phpexcel_iofactory::createwriter ($excel, ' Excel5 '); $objWriter->save (Str_replace('. php ', '. xls ',__file__));


PHP Export Excel

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.