Home Backend Development PHP Tutorial Using PHPExcel to export Excel example code in Yii_PHP tutorial

Using PHPExcel to export Excel example code in Yii_PHP tutorial

Jul 13, 2016 pm 05:06 PM
excel p phpexcel yii introduce code use use exist Example Export article frame

This article will introduce to you the specific method of using the PHPExcel plug-in in the yii framework to quickly export excel data. Students who are using yii may want to refer to it.

Recently I have been studying the Yii framework of PHP and I like it very much. When I encountered the problem of exporting Excel, I studied it and came up with the following method:

1. First add a reference to PHPExcel in cofig/main.php. My method is 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 "protected/extensions/" directory of the project.

3. Modify the Autoloader.php file in the PHPExcel code directory according to the following code:

          return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));*/          $functions = spl_autoload_functions();
The code is 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(array('PHPExcel_Autoloader','Load')),$functions);
            foreach ( $functions as $function)
                $x = spl_autoload_register($function);
            return $x;
 
    }    //    function Register()
Copy code


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');

}
 代码如下 复制代码

$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');

// Register ourselves with SPL
              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() In the above function, the original code is commented out. 4. The following code outputs Excel and some common property settings in your Controller:
The code is as follows Copy code
$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');

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630690.htmlTechArticleThe article will introduce to you the specific method of using the PHPExcel plug-in to quickly export excel data in the yii framework. There are Students who use Yii may want to check it out for reference. I’ve been studying PHP recently...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to evaluate the cost-effectiveness of commercial support for Java frameworks How to evaluate the cost-effectiveness of commercial support for Java frameworks Jun 05, 2024 pm 05:25 PM

Evaluating the cost/performance of commercial support for a Java framework involves the following steps: Determine the required level of assurance and service level agreement (SLA) guarantees. The experience and expertise of the research support team. Consider additional services such as upgrades, troubleshooting, and performance optimization. Weigh business support costs against risk mitigation and increased efficiency.

Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Jun 12, 2024 pm 08:38 PM

Since the launch of ChatGLM-6B on March 14, 2023, the GLM series models have received widespread attention and recognition. Especially after ChatGLM3-6B was open sourced, developers are full of expectations for the fourth-generation model launched by Zhipu AI. This expectation has finally been fully satisfied with the release of GLM-4-9B. The birth of GLM-4-9B In order to give small models (10B and below) more powerful capabilities, the GLM technical team launched this new fourth-generation GLM series open source model: GLM-4-9B after nearly half a year of exploration. This model greatly compresses the model size while ensuring accuracy, and has faster inference speed and higher efficiency. The GLM technical team’s exploration has not

Detailed introduction of Samsung S24ai functions Detailed introduction of Samsung S24ai functions Jun 24, 2024 am 11:18 AM

2024 is the first year of AI mobile phones. More and more mobile phones integrate multiple AI functions. Empowered by AI smart technology, our mobile phones can be used more efficiently and conveniently. Recently, the Galaxy S24 series released at the beginning of the year has once again improved its generative AI experience. Let’s take a look at the detailed function introduction below. 1. Generative AI deeply empowers Samsung Galaxy S24 series, which is empowered by Galaxy AI and brings many intelligent applications. These functions are deeply integrated with Samsung One UI6.1, allowing users to have a convenient intelligent experience at any time, significantly improving the performance of mobile phones. Efficiency and convenience of use. The instant search function pioneered by the Galaxy S24 series is one of the highlights. Users only need to press and hold

What is Bitget Launchpool? How to use Bitget Launchpool? What is Bitget Launchpool? How to use Bitget Launchpool? Jun 07, 2024 pm 12:06 PM

BitgetLaunchpool is a dynamic platform designed for all cryptocurrency enthusiasts. BitgetLaunchpool stands out with its unique offering. Here, you can stake your tokens to unlock more rewards, including airdrops, high returns, and a generous prize pool exclusive to early participants. What is BitgetLaunchpool? BitgetLaunchpool is a cryptocurrency platform where tokens can be staked and earned with user-friendly terms and conditions. By investing BGB or other tokens in Launchpool, users have the opportunity to receive free airdrops, earnings and participate in generous bonus pools. The income from pledged assets is calculated within T+1 hours, and the rewards are based on

How does the learning curve of PHP frameworks compare to other language frameworks? How does the learning curve of PHP frameworks compare to other language frameworks? Jun 06, 2024 pm 12:41 PM

The learning curve of a PHP framework depends on language proficiency, framework complexity, documentation quality, and community support. The learning curve of PHP frameworks is higher when compared to Python frameworks and lower when compared to Ruby frameworks. Compared to Java frameworks, PHP frameworks have a moderate learning curve but a shorter time to get started.

How do the lightweight options of PHP frameworks affect application performance? How do the lightweight options of PHP frameworks affect application performance? Jun 06, 2024 am 10:53 AM

The lightweight PHP framework improves application performance through small size and low resource consumption. Its features include: small size, fast startup, low memory usage, improved response speed and throughput, and reduced resource consumption. Practical case: SlimFramework creates REST API, only 500KB, high responsiveness and high throughput

The Mistral open source code model takes the throne! Codestral is crazy about training in over 80 languages, and domestic Tongyi developers are asking to participate! The Mistral open source code model takes the throne! Codestral is crazy about training in over 80 languages, and domestic Tongyi developers are asking to participate! Jun 08, 2024 pm 09:55 PM

Produced by 51CTO technology stack (WeChat ID: blog51cto) Mistral released its first code model Codestral-22B! What’s crazy about this model is not only that it’s trained on over 80 programming languages, including Swift, etc. that many code models ignore. Their speeds are not exactly the same. It is required to write a "publish/subscribe" system using Go language. The GPT-4o here is being output, and Codestral is handing in the paper so fast that it’s hard to see! Since the model has just been launched, it has not yet been publicly tested. But according to the person in charge of Mistral, Codestral is currently the best-performing open source code model. Friends who are interested in the picture can move to: - Hug the face: https

Solve complex financial calculations with 3 Excel financial functions Solve complex financial calculations with 3 Excel financial functions Jul 21, 2024 pm 06:39 PM

Original title: "These 3 Excel financial functions are undervalued again!" 》Author of this article: Xiaohua Editor of this article: Zhu Lan Recently, Xiaohua encountered an interesting question, which came from the soul of an old friend: How to choose between monthly annuity and private mutual insurance finance? The basic information of these two financial products is as follows: Monthly annuity: monthly payment of 1,000 yuan, annualized interest rate of 3%, 2-year term, and one-time withdrawal of principal and interest upon maturity. Mutual insurance finance: Pay a principal of 1,000 yuan every month, and the monthly principal will be calculated at 10% interest, with a 2-year term. There are 24 people participating in the same product. Every month, one person must receive all the principal and interest paid by others. The next month after receiving the payment, one person must pay an interest of 100 yuan/month. How to compare the pros and cons of these two financial products? we can

See all articles