PHP Export Excel table

Source: Internet
Author: User

What we are saying today is that PHP exports Excel tables, which are also needed for many projects.

First download Phpexcel, no can to (any site) http://phpexcel.codeplex.com/releases/view/119187 download Phpexcel This package, of course, there are level of pro can write their own one. Download good after decompression, extract the direct reference, it is necessary to extract after the file

Second, include in PHP

Finally, the rest of the code is attached, relatively concise. If you need other Excel features, look at my previous essays.

$objPHPExcel = new Phpexcel ();

$objWriter = Phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel5 ');
Ob_end_clean ();
Header (' Content-type:application/vnd.ms-excel ');
Header (' Content-type:text/xls; Charset=utf-8 ');
Header (' Content-disposition:attachment;filename= ' vault Settlement Day report. xls "');
Header (' cache-control:max-age=0 ');
$objPHPExcel->getactivesheet ()->settitle (' Vault Settlement Day Report ');//Set the name value of the sheet
$objPHPExcel->getproperties ()->setcreator ("I");//Set Creator


//Set cell information
$objPHPExcel->setactivesheetindex (0)
->setcellvalue (' A1 ', ' excavation Method: ')
- Setcellvalue (' F1 ', ' surrounding rock Category: ')
->setcellvalue (' A2 ', ' palm facet mileage ')
->setcellvalue (' C2 ', ' two liner Miles ')
Setcellvalue (' E2 ', ' tilt-arch mileage ')
->setcellvalue (' G2 ', ' two-liner-to-face ' distance ')
->setcellvalue (' I2 ', ' tilt-to-face ' distance ')
- Setcellvalue (' A5 ', ' Test point number ')
->setcellvalue (' B5 ', ' date of placement ')
->setcellvalue (' C5 ', ' Measurement time ')
- Setcellvalue (' D5 ', ' observed value (M) ')
->setcellvalue (' E5 ', ' last observed (M) ')
->setcellvalue (' F5 ', ' last observed value (M) ')
- >setcellvalue (' G5 ', ' total sedimentation (mm) ')
->setcellvalue (' H5 ', ' relative to last settlement (mm) ')
->setcellvalue (' I5 ', ' time interval ')
->setcellvalue (' J5 ', ' settling rate (nm/d) ')
->setcellvalue (' K5 ', ' remarks ');

Merge cells
$objPHPExcel->getactivesheet ()->mergecells (' a1:e1 ');//Standard method
$objPHPExcel->getactivesheet ()//big opening method of brain hole
->mergecells (' a2:a4 ')
->mergecells (' b2:b4 ')
->mergecells (' C2:c4 ')
->mergecells (' D2:d4 ')
->mergecells (' E2:e4 ')
->mergecells (' F2:f4 ')
->mergecells (' G2:g4 ')
->mergecells (' H2:h4 ')
->mergecells (' I2:i4 ')
->mergecells (' J2:j4 ')
->mergecells (' K2:k4 ')
->mergecells (' A5:a6 ')
->mergecells (' B5:b6 ')
->mergecells (' C5:c6 ')
->mergecells (' D5:d6 ')
->mergecells (' E5:e6 ')
->mergecells (' F5:f6 ')
->mergecells (' G5:g6 ')
->mergecells (' H5:h6 ')
->mergecells (' I5:i6 ')
->mergecells (' j5:j6 ')
->mergecells (' k5:k6 ');

Set protection cells
/* $objPHPExcel->getactivesheet ()->getprotection ()->setsheet (true);
/* $objPHPExcel->getactivesheet ()->protectcells (' a2:k6 '); */

$objWriter->save (' php://output ');

PHP Export Excel table

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.