Phpexcel Export An Introduction to Excel tutorial

Source: Internet
Author: User
Tags first row

Phpexcel is a powerful Excel export/import plug-in, it can even export PDFs, etc., is a very useful PHP plug-ins, PHP learning is essential. So how do you use it, here's the Phpexcel entry paradigm:

PHP Source Reference:

<?php
Require_once ("phpexcel/phpexcel.php");
$excel = new Phpexcel (); Instantiate the Phpexcel class

Set author (not necessary)
$excel->getproperties ()->setcreator ("Reson");

The following is the data to be exported
$datas = Array (
Array
0 => ' UID ',
1 => ' username ',
2 => ' sex '
),
Array
0 => ' 1 ',
1 => ' Reson ',
2 => ' Men '
),
Array
0 => ' 2 ',
1 => ' Anyse ',
2 => ' female '
)
);

Start exporting. Note that $i starts at 1 and cannot start at 0 for the following reasons: ' A '. $i, when I=1 is A1 (first row, first lattice)
$i = 1;
foreach ($datas as $key => $val) {
$excel->getactivesheet ()->setcellvalue (' A '. $i, $val [' 0 ']);
$excel->getactivesheet ()->setcellvalue (' B '. $i, $val [' 1 ']);
$excel->getactivesheet ()->setcellvalue (' C '. $i, $val [' 2 ']);
$i + +;
}

$excel->getactivesheet ()->settitle (' PHP learner list '); meaning See the following figure

$fileName = ' Test ';
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= '. $fileName. ') XLS "');
Header ("Content-transfer-encoding:binary");

$objWriter = Phpexcel_iofactory::createwriter ($excel, ' Excel5 ');
$objWriter->save (' php://output ');
?>




This is the way it is, is it very easy to use it?

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.