Of course download und put it under extensions folder, so the PHPExcel.php is in root of extensions, near PHPExcel folder.
then add to main.php this lines
// application components
'components'=>array(
'excel'=>array(
'class'=>'application.extensions.PHPExcel',
),
and now just modify /protected/extensions/PHPExcel/Autoloader.php
change proc PHPExcel_Autoloader.Register as follows:
public static function Register() {
$functions = spl_autoload_functions();
foreach($functions as $function)
spl_autoload_unregister($function);
$functions=array_merge(array(array('PHPExcel_Autoloader', 'Load')), $functions);
foreach($functions as $function)
$x = spl_autoload_register($function);
return $x;
}// function Register()
now you can use PHPExcel as it described in its manual in yii controllers or models.
for example like this:
public function actionExcel(){
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello')
->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!');
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A4', 'Miscellaneous glyphs')
->setCellValue('A5', 'eaeuaeioueiuyaouc');
$objPHPExcel->getActiveSheet()->setTitle('Simple');
$objPHPExcel->setActiveSheetIndex(0);
ob_end_clean();
ob_start();
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="test.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}
lines
ob_end_clean();
ob_start();
are neccessary (may be only for me) 'cause there are some garbage in the output buffer without them, and xls file is corrupted

Help


















