Methods of using Phpexcel to export excel in Yii, yiiphpexcel_php tutorial

Source: Internet
Author: User
Tags autoloader spl

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 ...

  • 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.