PHP Excel file export problem! Solution saving ~~

Source: Internet
Author: User
First paste the code: {code...} to export the following error:

Post Code first:

Public function check_daochu ($ data) {$ this-> load-> library ('phpexcel '); $ this-> load-> library ('phpexcel/IOFactory '); $ objPHPExcel = new PHPExcel (); $ objWriter = new PHPExcel_Writer_Excel2007 ($ objPHPExcel); // set the header $ this-> Excel_bt ($ objPHPExcel, $ data ['bt _ data']); // exported class capacity $ this-> Excel_lr ($ objPHPExcel, $ data ['data']); // set the cell width $ objPHPExcel-> getActiveSheet ()-> getColumnDimension ('B')-> setWidth (15 ); foreach ($ data ['hb _ data'] as $ key => $ value) {// merge cells $ objPHPExcel-> getActiveSheet ()-> mergeCells ($ key. ':'. $ value);} // horizontal vertical center setting $ objPHPExcel-> getActiveSheet ()-> getStyle ('a1')-> getAlignment ()-> setVertical (PHPExcel_Style_Alignment :: VERTICAL_CENTER); $ objPHPExcel-> getActiveSheet ()-> getStyle ('a1')-> getAlignment ()-> setHorizontal (PHPExcel_Style_Alignment: HORIZONTAL_CENTER ); $ fieldname = iconv ('utf-8', 'gb2312', date ("Y-m-d", time ()). '_'. $ data ['bt _ data'] ['a1']); ob_end_clean (); header ("Pragma: public"); header ("Expires: 0 "); 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 "); header ('content-Disposition: attachment; filename = "'. $ fieldname. '.xlsx "'); header (" Content-Transfer-Encoding: binary "); $ objWriter-> save ('php: // output ');} // set the export title to public function Excel_bt ($ objPHPExcel, $ bt_data) {foreach ($ bt_data as $ key => $ value) {$ objPHPExcel-> getActiveSheet () -> setCellValue ($ key, $ value) ;}// set the exported public function Excel_lr ($ objPHPExcel, $ select_data) {$ I = 3; $ data = array ('A', 'B', 'C', 'D', 'E', 'E', 'F', 'G', 'h ', 'I', 'J', 'k', 'l', 'M', 'n', 'O', 'P', 'Q', 'R ', 'S ', 't', 'U', 'V', 'w', 'x', 'y', 'z '); foreach ($ select_data as $ key = >$ value) {$ j = 0; foreach ($ value as $ k = >$ v) {$ objPHPExcel-> getActiveSheet () -> setCellValue ($ data [$ j]. $ I, $ v); $ j ++;} $ I ++ ;}}

The following error occurs during export:

Reply content:

Post Code first:

Public function check_daochu ($ data) {$ this-> load-> library ('phpexcel '); $ this-> load-> library ('phpexcel/IOFactory '); $ objPHPExcel = new PHPExcel (); $ objWriter = new PHPExcel_Writer_Excel2007 ($ objPHPExcel); // set the header $ this-> Excel_bt ($ objPHPExcel, $ data ['bt _ data']); // exported class capacity $ this-> Excel_lr ($ objPHPExcel, $ data ['data']); // set the cell width $ objPHPExcel-> getActiveSheet ()-> getColumnDimension ('B')-> setWidth (15 ); foreach ($ data ['hb _ data'] as $ key => $ value) {// merge cells $ objPHPExcel-> getActiveSheet ()-> mergeCells ($ key. ':'. $ value);} // horizontal vertical center setting $ objPHPExcel-> getActiveSheet ()-> getStyle ('a1')-> getAlignment ()-> setVertical (PHPExcel_Style_Alignment :: VERTICAL_CENTER); $ objPHPExcel-> getActiveSheet ()-> getStyle ('a1')-> getAlignment ()-> setHorizontal (PHPExcel_Style_Alignment: HORIZONTAL_CENTER ); $ fieldname = iconv ('utf-8', 'gb2312', date ("Y-m-d", time ()). '_'. $ data ['bt _ data'] ['a1']); ob_end_clean (); header ("Pragma: public"); header ("Expires: 0 "); 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 "); header ('content-Disposition: attachment; filename = "'. $ fieldname. '.xlsx "'); header (" Content-Transfer-Encoding: binary "); $ objWriter-> save ('php: // output ');} // set the export title to public function Excel_bt ($ objPHPExcel, $ bt_data) {foreach ($ bt_data as $ key => $ value) {$ objPHPExcel-> getActiveSheet () -> setCellValue ($ key, $ value) ;}// set the exported public function Excel_lr ($ objPHPExcel, $ select_data) {$ I = 3; $ data = array ('A', 'B', 'C', 'D', 'E', 'E', 'F', 'G', 'h ', 'I', 'J', 'k', 'l', 'M', 'n', 'O', 'P', 'Q', 'R ', 'S ', 't', 'U', 'V', 'w', 'x', 'y', 'z '); foreach ($ select_data as $ key = >$ value) {$ j = 0; foreach ($ value as $ k = >$ v) {$ objPHPExcel-> getActiveSheet () -> setCellValue ($ data [$ j]. $ I, $ v); $ j ++;} $ I ++ ;}}

The following error occurs during export:

What does your failure mean?

register_shutdown_function(function(){    $lastError = error_get_last();    if ($lastError) {        error_log(json_encode($lastError));    }});

Open it in notepad to see if there is any error.
Generally, this is an error.

I still cannot find the reason for my previous post.

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.