先贴代码:
public function check_daochu($data) { $this->load->library('phpexcel'); $this->load->library('phpexcel/iofactory'); $objphpexcel = new phpexcel(); $objwriter = new phpexcel_writer_excel2007($objphpexcel); //设置表头 $this->excel_bt($objphpexcel, $data['bt_data']); //导出的类容 $this->excel_lr($objphpexcel, $data['data']); //设置单元格的宽度 $objphpexcel->getactivesheet()->getcolumndimension('b')->setwidth(15); foreach ($data['hb_data'] as $key => $value) { //合并单元格 $objphpexcel->getactivesheet()->mergecells($key . ':' . $value); } //水平垂直居中设置 $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'); }//设置导出标题的方法 public function excel_bt($objphpexcel, $bt_data) { foreach ($bt_data as $key => $value) { $objphpexcel->getactivesheet()->setcellvalue($key, $value); } } //设置导出的内容 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++; } }
导出出现如下的错误:
回复内容: 先贴代码:
public function check_daochu($data) { $this->load->library('phpexcel'); $this->load->library('phpexcel/iofactory'); $objphpexcel = new phpexcel(); $objwriter = new phpexcel_writer_excel2007($objphpexcel); //设置表头 $this->excel_bt($objphpexcel, $data['bt_data']); //导出的类容 $this->excel_lr($objphpexcel, $data['data']); //设置单元格的宽度 $objphpexcel->getactivesheet()->getcolumndimension('b')->setwidth(15); foreach ($data['hb_data'] as $key => $value) { //合并单元格 $objphpexcel->getactivesheet()->mergecells($key . ':' . $value); } //水平垂直居中设置 $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'); }//设置导出标题的方法 public function excel_bt($objphpexcel, $bt_data) { foreach ($bt_data as $key => $value) { $objphpexcel->getactivesheet()->setcellvalue($key, $value); } } //设置导出的内容 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++; } }
导出出现如下的错误:
你的不行指的是什么?
register_shutdown_function(function(){ $lasterror = error_get_last(); if ($lasterror) { error_log(json_encode($lasterror)); }});
你用记事本打开看下有没有报错
一般这种情况是出错了
以前的帖子,还是没找到原因呢