The method of using Phpexcel to export excel in Yii, Yiiphpexcel
The example in this article describes how to export Excel using Phpexcel in Yii. Share to everyone for your reference. The specific analysis is as follows:
Recently in the study of the YII framework of PHP, like, encountered the problem of exporting Excel, studied a bit, there are the following methods.
1, first add a reference to the Phpexcel in cofig/main.php, my method is this, the code is as follows:
Copy the Code Code as follows://autoloading model and component classes
' Import ' =>array (
/* ' Application.modules.srbac.controllers.SBaseController ', */
' Application.models.* ',
' Application.components.* ',
' Application.extensions.phpexcel.* ',
),
2, of course, remember to copy the entire Phpexcel directory to the project's "protected/extensions/" directory.
3, follow the code below to modify the autoloader.php file in the Phpexcel code directory, the code is as follows:
Copy the code code as follows: public static function Register () {
/*if (function_exists (' __autoload ')) {
//Register any existing autoloader function with SPL, so we Don ' t get any clashes
Spl_autoload_register (' __autoload ');
}
//Register ourselves with SPL
return Spl_autoload_register (Array (' Phpexcel_autoloader ', ' Load ')); */
$functions = Spl_autoload_functions ();
foreach ($functions as $function)
Spl_autoload_unregister ($function);
$functions = array_merge (Array (' Phpexcel_autoloader ', ' Load '), $functions);
foreach ($functions as $function)
$x = Spl_autoload_register ($function);
return $x; In the function above
}//Function Register ()
, the original code is commented out.
4, the following code is the output of Excel, as well as some common property settings, in your controller, the code is as follows:
Copy the Code code as follows: $objectPHPExcel = new Phpexcel ();
$objectPHPExcel->setactivesheetindex (0);
Ob_end_clean ();
Ob_start ();
Header (' Content-type:application/vnd.ms-excel ');
Header (' content-disposition:attachment;filename= ' '. ') xiaoqiang-'. Date ("YMJ"). XLS "');
$objWriter = Phpexcel_iofactory::createwriter ($objectPHPExcel, ' Excel5 ');
$objWriter->save (' php://output ');
It is hoped that this article is helpful to the PHP program design based on YII framework.
http://www.bkjia.com/PHPjc/933603.html www.bkjia.com true http://www.bkjia.com/PHPjc/933603.html techarticle The method of using Phpexcel to export excel in Yii, Yiiphpexcel This example describes the method of using Phpexcel to export excel in Yii. Share to everyone for your reference. The specific analysis is as follows: recently in ...