Welcome Guest, Not a member yet? Register   Sign In
PHPExcel as plugin
#1

[eluser]richardporteous[/eluser]
[[CategoryTongueHPExcel]]

This has got to be one of the most EASY ways to add PHPExcel with NO changes
(after searching and finding less satisfactory answers)

NOTE: I use Ubuntu desktop, Netbeans, PHP5, codeigniter1.7.2, and PHPExcel 1.7.3c.

create a file phpexcel_pi.php in your plugins folder (under application)
add these 4 lines to it

<?php
/** phpexcel_pi.php **/
require_once APPPATH.’/plugins/phpexcel/PHPExcel.php’;
require_once APPPATH.’/plugins/phpexcel/PHPExcel/IOFactory.php’;


then download and extract the phpexcel files
take the classes folder from the extracted files and place it in the plugins folder with the name ‘phpexcel’ instead of classes (or you could leave the same but change the above file)

the following example will place a file in a reports folder
place this function in a class (borrowed form a similar article)

public function excel()
{
$this->load->plugin(‘phpexcel’);

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

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

$objPHPExcel->createSheet();
$objPHPExcel->setActiveSheetIndex(1);
$objPHPExcel->getActiveSheet()->setCellValue(“A1”, “cell value here 222”);
// Save it as an excel 2003 file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, “Excel5”);
$objWriter->save(“reports/nameoffile.xls”);
//if writing direct to browser (download) you could place an 'exit' here
}


you will see that you can do most from the PHPExcel examples with very little changes




I posted this elsewhere - it went under article discussions (sorry maintainers) Sad
#2

[eluser]richardporteous[/eluser]
In CI 2.0 helpers (instead of plugins) can be used with minor changes

$this->load->helper(‘phpexcel’); //not load->plugin

<?php
/** phpexcel_helper.php */ // _helper not _pi
require_once APPPATH.‘helpers/phpexcel/PHPExcel.php’;
require_once APPPATH.‘helpers/phpexcel/PHPExcel/IOFactory.php’;

rest works as before




Theme © iAndrew 2016 - Forum software by © MyBB