1. Go to http://phpexcel.codeplex.com/download Phpexcel source code, unzip the Phpexcel/classes Phpexcel folder and phpexcel.php copy to CI application/ In the Libraries folder. The directory structure is as follows:
---application/libraries/phpexcel.php
---application/libraries/phpexcel (folder)
2. Modify the application/libraries/phpexcel/iofactory.php file: Change its class name from Phpexcel_iofactory to Iofactory, follow the CI class naming convention, and change its constructor to public
3. Use of Phpexcel within CI:
//classes that load Phpexcel$this->load->library (' Phpexcel ');$this->load->library (' Phpexcel/iofactory ');//Creating an Phpexcel instance$excel=NewPhpexcel ();//Here are some of the actions you'll use for Excel in your project//assign a value to a cell$excel->getactivesheet ()->setcellvalue (' A1 ', ' AAA ');//Merge Cells$excel->getactivesheet ()->mergecells (' A1:a2 '));//set text in cells to center vertically$excel->getactivesheet ()->getstyle (' A1 ')->getalignment ()->setvertical (phpexcel_style_alignment::vertical_center);//set text wrapping in cells$excel->getactivesheet ()->getstyle (' A1 ')->getalignment ()->setwraptext (true);//Add a comment to a cell$excel->getactivesheet ()->getcomment (' A1 ')->gettext ()->createtextrun (' Hello '));//Set cell text color$excel->getactivesheet ()->getstyle (' A1 ')->getfont ()->getcolor->setargb (Phpexcel_style_color::color_red);//Output to Browser$write=NewPhpexcel_writer_excel2007 ($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= ' test.xlsx "');Header("Content-transfer-encoding:binary");$write->save (' php://output ');
CodeIgniter using Phpexcel