CodeIgniter using Phpexcel

Source: Internet
Author: User
Tags codeigniter

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

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.