Exporting data from php to excel

后端 未结 5 438
逝去的感伤
逝去的感伤 2020-12-08 22:23

I need to export data from php (data retrieved from mysql database) to excel. I\'m using Zend Framework. I need to do some changes to my data before exporting to excel. Actu

5条回答
  •  离开以前
    2020-12-08 22:50

    I would suggest you to use great PHPExcel library. It is really powerful, supports variety of formats, can do visual formatting and is easy to use.

    You can find more about it at their webpage: http://phpexcel.codeplex.com/. (PHPExcel has already moved at https://github.com/PHPOffice/PHPExcel)

    2019:

    PHPExcel has now been superceded by PhpSpreadsheet GitHub .

    Example of usage:

        $objPHPExcel = new PHPExcel();
        /** You can set many properties */
        $objPHPExcel->getProperties()->setCreator("My company")
                     ->setLastModifiedBy("John Doe")
                     ->setTitle("Annual report")
                     ->setSubject("Sales")
                     ->setDescription("Annual sales report by John Doe")
                     ->setCategory("Finance");
    
        /** Choose one of sheets */
        $activeSheet = $objPHPExcel->setActiveSheetIndex(0);
        /** Simply set value of cell */
        $activeSheet->setCellValue("A1", 'plural');
    

    You can do a lot more of course, reading excel files, setting visual styles, creating plots, expressions and lot more.

提交回复
热议问题