PHP Export Example of Excel, export an example of Excel _php tutorial

Source: Internet
Author: User

PHP Export Example of Excel, export an example of Excel to explain


This implementation of PHP exported Excel file using PHP Open source program phpexcel, some key code to share to everyone, the specific content is as follows

<?phperror_reporting (E_all);d ate_default_timezone_set (' Asia/shanghai '); require_once './Classes/PHPExcel.php ' ; $data =array (0=>array ' id ' =>1001, ' username ' and ' Zhang Fei ', ' password ' = ' 123456 ', ' address ' = ' and ' The Three Kingdoms ' Gao 250 Lane, Room 101 '), 1=>array (' id ' =>1002, ' username ' = ' Guan Yu ', ' password ' = ' 123456 ', ' address ' = ' + ' When the Three Kingdoms Huaguoshan  '), 2=>array (' id ' =>1003, ' username ' = ' cao ', ' password ' = ' 123456 ', ' address ' = ' 2055 Lane 3rd Yanan West Road ' ), 3=>array (' id ' =>1004, ' username ' and ' Liu Bei ', ' password ' = ' 654321 ', ' Address ', ' No. 188th, ' Yu Yuan Road, Room 3309 ') ; $objPHPExcel =new Phpexcel (); $objPHPExcel->getproperties ()->setcreator (' http://www.bkjia.com ')->se Tlastmodifiedby (' http://www.bkjia.com ')->settitle (' Office of XLSX Document ')->setsub Ject (' Office $ xlsx Document ')->setdescription (' Document for Office ' xlsx, generated using PHP cl               Asses. ') ->setkeywOrds (' Office openxml php ')->setcategory (' Result file '); $objPHPExcel->setactivesheetindex (0) ->setcellvalue (' A1 ', ' ID ')->setcellvalue (' B1 ', ' username ')->setcellvalue (' C1 ', ' Password ')->setcellvalue (     ' D1 ', ' address '); $i = 2; foreach ($data as $k = + $v) {$objPHPExcel->setactivesheetindex (0)->setcellvalue (' A '. $i, $v [' id '])->se Tcellvalue (' B '. $i, $v [' username '])->setcellvalue (' C ' $i, $v [' Password '])->setcellvalue (' D '. $i, $v [' Address '  ]); $i + +;} $objPHPExcel->getactivesheet ()->settitle (' Third grade 2 '); $objPHPExcel->setactivesheetindex (0); $filename = UrlEncode (' Student information tables '). ' _ '. Date (' Y-m-dhis '); Generate xlsx file/*header (' Content-type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet '); Header (' Content-disposition:attachment;filename= "'. $filename. '. Xlsx "'); header (' cache-control:max-age=0 '); $objWriter =phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel2007 ') ); *///generates the XLS file header (' content-type:application/vnd.ms-Excel '); header (' Content-disposition:attachment;filename= '. $filename. XLS "'); header (' cache-control:max-age=0 '); $objWriter = Phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel5 '); $ Objwriter->save (' Php://output '); exit;

Note: If garbled when exporting Chinese, you can try to convert the string to gb2312 code similar to the following:

View Code Printing

$str =mb_convert_encoding ("gb2312", "UTF-8", $str);

The above is the whole content of this article, I hope that everyone's study has helped.

Articles you may be interested in:

    • How PHP exports a database to Excel
    • PHP export MySQL data to Excel file (fputcsv)
    • Phpexcel a solution to a memory overflow error when exporting large amounts of data
    • The small experience of exporting Excel based on PHP perfectly solves the garbled problem
    • PHP-based export to Excel or CSV (with UTF8, GBK encoding conversion)
    • PHP Import Export Excel instance
    • Import and export of Excel data using Phpexcel (full step detailed parsing)
    • Using Phpexcel to import Excel into database and database to export Excel implementation
    • Thinkphp using Phpexcel to implement Excel data import Export full instance

http://www.bkjia.com/PHPjc/1095277.html www.bkjia.com true http://www.bkjia.com/PHPjc/1095277.html techarticle PHP Export Excel instance to explain, export Excel instance explained this implementation PHP export Excel file using PHP Open source program phpexcel, some key code share to everyone, the specific content as follows ph ...

  • 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.