PHP export Excel file Problem! Ask for salvation ~ ~

Source: Internet
Author: User
Keywords Php

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 Header $this->excel_bt ($objPHPExcel, $data [' bt_data ']);        The exported class capacity $this->EXCEL_LR ($objPHPExcel, $data [' data ']);        Sets the width of the cell $objPHPExcel->getactivesheet ()->getcolumndimension (' B ')->setwidth (15); foreach ($data [' Hb_data '] as $key = + $value) {//merged cells $objPHPExcel->getactivesheet ()->merg Ecells ($key. ':' .        $value); }//Horizontal vertical centering setting $objPHPExcel->getactivesheet ()->getstyle (' A1 ')->getalignment ()->setvertical (phpexce        L_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 method for exporting headers public function excel_bt ($objPHPExcel, $bt _data) {foreach ($bt _data as $key + $value) {        $objPHPExcel->getactivesheet ()->setcellvalue ($key, $value);        }}//Set the exported content public function Excel_lr ($objPHPExcel, $select _data) {$i = 3; $data = Array (' A ', ' B ', ' C ', ' D ', ' 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 occurred in the export:

Reply content:

Paste the 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 Header $this->excel_bt ($objPHPExcel, $data [' bt_data ']);        The exported class capacity $this->EXCEL_LR ($objPHPExcel, $data [' data ']);        Sets the width of the cell $objPHPExcel->getactivesheet ()->getcolumndimension (' B ')->setwidth (15); foreach ($data [' Hb_data '] as $key = + $value) {//merged cells $objPHPExcel->getactivesheet ()->merg Ecells ($key. ':' .        $value); }//Horizontal vertical centering setting $objPHPExcel->getactivesheet ()->getstyle (' A1 ')->getalignment ()->setvertical (phpexce        L_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 method for exporting headers public function excel_bt ($objPHPExcel, $bt _data) {foreach ($bt _data as $key + $value) {        $objPHPExcel->getactivesheet ()->setcellvalue ($key, $value);        }}//Set the exported content public function Excel_lr ($objPHPExcel, $select _data) {$i = 3; $data = Array (' A ', ' B ', ' C ', ' D ', ' 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 occurred in the export:

What do you mean by that?

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

You open it with a notepad to see if there's an error.
Normally, this is a mistake.

The previous post, still did not find the reason?

  • Related Article

    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.