Phpexcel Exporting data tables

Source: Internet
Author: User

1. Download Phpexcel

2. Introduce the Phpexcel class file to the page and create the object of the class

include (".. /chajian/phpexcel/classes/phpexcel.php "); $excel New Phpexcel ();

3. Query the database to get a two-dimensional array here the array is named: $attr

4. Export Excel code, table header array and data array corresponding to:

//Excel table format, where 10 columns are briefly written$letter=Array(' A ', ' B ', ' C ', ' D ', ' E ', ' f ', ' f ', ' G ', ' H ', ' I ');//Table Header Array$tableheader=Array(' Reporting time ', ' reporting complete ', ' reporting staff ', ' final accomplishment ', ' tutor reviews ');//Populating header information for($i= 0;$i<Count($tableheader);$i++) {$excel->getactivesheet ()->setcellvalue ("$letter[$i]1 ","$tableheader[$i]");}//Populating table Information for($i= 2;$i<=Count($attr) + 1;$i++) {$j= 0;foreach($attr[$i-2] as $key=$value) {$excel->getactivesheet ()->setcellvalue ("$letter[$j]$i","$value");$j++;}}//Create an Excel input object$write=NewPhpexcel_writer_excel5 ($excel);Header("Pragma:public");Header("expires:0");Header("Cache-control:must-revalidate, post-check=0, pre-check=0");Header("Content-type:application/force-download");Header("Content-type:application/vnd.ms-execl");Header("Content-type:application/octet-stream");Header("Content-type:application/download");;Header("Content-disposition:attachment;filename= ' {$SJ}_{$BT} job. xls ' ");Header("Content-transfer-encoding:binary");$write->save (' php://output ');

5. If the long digit string is displayed as a scientific counting solution

(1) Specify the type of data to display when setting the value

$excel->getactivesheet ()->setcellvalueexplicit (' D1 ', 120000000000,phpexcel_cell_datatype::type_ STRING);

(2) Add a space before the numeric string to make it a string

$excel->getactivesheet ()->setcellvalue (' D1 ', '. 120000000000);

Phpexcel Exporting data tables

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.