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?