Skip to content
Derek Jones edited this page Jul 5, 2012 · 3 revisions

In order to get PHPExcel http://www.codeplex.com/PHPExcel working with CodeIgniter, there are a few steps you must take to ensure compatibility with CodeIgniter's naming standards.

1: Class names must match the file names. PHPExcel has a few files(such as PHPExcel/IOFactory.php) that have names like PHPExcel_IOFactory. Change these names by removing the "PHPExcel_" part. These constructors in these files must be public in order for CI to access them.

  1. To load a library like the IOFactory, simply say: $this->load->library('PHPExcel/iofactory');

An simple use case of PHPExcel would look like:

$this->load->library('phpexcel'); $this->load->library('PHPExcel/iofactory');

$objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setTitle("title") ->setDescription("description");

// Assign cell values $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->setCellValue('A1', 'cell value here');

// Save it as an excel 2003 file $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save("nameoffile.xls");

Clone this wiki locally