Yii? Exporting data with Phpexcel

Source: Internet
Author: User
I used Yii to build a background, in the background page to add the Export button click the Export button is to export the current page data to a table how to do this function?? Before that, I tried using phpexcel to export the example with Phpexcel, but I threw the exported method to the controller, and when I called it with Index.php?r=tips/excel, I showed Notfount




Reply to discussion (solution)

1. Put the phpexcel inside the extension.
2.main.php introduced ' extensions. Phpexcel.classes.* ';
3. Write your own export code
4.1-2 not, I can not help you, 3 not, just refer to the Phpexcel example

Below I give an example of my own writing, I am directly importing an Excel class that you can load when the component is loaded. Look at a person's liking

Yii::import (' application.extensions.phpexcel.classes.* ');        $objPHPExcel = new Phpexcel ();            $objPHPExcel->getproperties ()->setcreator ("Maarten Balliauw")->setlastmodifiedby ("Maarten Balliauw")            ->settitle ("Office" xlsx Test Document ")->setsubject (" Office "xlsx Test Document")            ->setdescription ("Test document for Office" XLSX, generated using PHP classes. ")        ->setkeywords ("Office openxml PHP")->setcategory ("Test result file");        $objPHPExcel->getactivesheet ()->settitle (' name ');        $objPHPExcel->setactivesheetindex (0);        $objWriter = new Phpexcel_writer_excel5 ($objPHPExcel);        Header ("Pragma:public");        Header ("expires:0");        Header (' Content-type:application/vnd.ms-excel;charset=utf8 ');        Header ("Cache-control:must-revalidate, Post-check=0, pre-check=0");        Header ("Content-type:application/force-download"); Header"Content-type:application/vnd.ms-execl");        Header ("Content-type:application/octet-stream");        Header ("Content-type:application/download");        $fireName = ' counting order ';        Header ("Content-disposition:attachment;filename= $fireName. xls");        Header ("Content-transfer-encoding:binary");        $objWriter->save ("Php://output");        Yii::app ()->end ();    Spl_autoload_register (Array (' yiibase ', ' autoload '));            }//long-term data export private function Defaulta ($objPHPExcel, $resource) {$objPHPExcel->setactivesheetindex (0)        ->setcellvalue (' A1 ', ' Order ID ')->setcellvalue (' B1 ', ' Order sn ') $i = 2; foreach ($resource as $row) {$objPHPExcel->setactivesheetindex (0)->setcellvalue ("A$i", $r            ow[' order_id ')->setcellvalue ("B$i", "$row [ORDER_SN]");        $i + +; }    }
  • 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.