How to export data to an excel file using PHPExcel

后端 未结 5 966
迷失自我
迷失自我 2020-12-02 21:01

I have taken the source code from limesurvey and have added the PHPExcel library to my limesurvey code to export data to an excel file after you click a link. Currently the

5条回答
  •  萌比男神i
    2020-12-02 21:34

    $this->load->library('excel');
    $file_name = 'Demo';
    $arrHeader = array('Name', 'Mobile');
    $arrRows = array(0=>array('Name'=>'Jayant','Mobile'=>54545), 1=>array('Name'=>'Jayant1', 'Mobile'=>44454), 2=>array('Name'=>'Jayant2','Mobile'=>111222), 3=>array('Name'=>'Jayant3', 'Mobile'=>99999));
    $this->excel->getActiveSheet()->fromArray($arrHeader,'','A1');
    $this->excel->getActiveSheet()->fromArray($arrRows);
    header('Content-Type: application/vnd.ms-excel'); //mime type
    header('Content-Disposition: attachment;filename="'.$file_name.'"'); //tell browser what's the file name
    header('Cache-Control: max-age=0'); //no cache
    $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
    $objWriter->save('php://output');
    

提交回复
热议问题