PHPExcel空白屏幕

时间:2016-09-18 21:00:22

标签: php codeigniter phpexcel

在这个特殊情况下已经发了很多帖子,我已经通过stackoverflow发布帖子,以确定为什么PHPExcel在导出带有给定代码的数据库数据后没有显示下载对话框,如下所示: / p>

// PHPExcel Code
$query = $this->reports_m->payreport_yr($yr,true);
if(!$query)return false;
$fields = $query->list_fields();
$this->excel->getProperties()->setTitle("Excel Export")->setDescription("Payment Report Excel Document");
$this->excel->getActiveSheet()->mergeCells('A1:D1');
//$this->excel->setActiveSheetIndex(0)->mergeCells('A1:D1');
//$this->excel->getActiveSheet()->getCell('A1')->setValue('This is the text that I want to see in the merged cells');
//$this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//activate worksheet number 1
$this->excel->setActiveSheetIndex(0);
$col = 0;
foreach ($fields as $field)
{
$this->excel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $headers[$field]);
$col++;
}
$first_letter = PHPExcel_Cell::stringFromColumnIndex(0);
$last_letter = PHPExcel_Cell::stringFromColumnIndex(count($fields)-1);
$header_range = "{$first_letter}1:{$last_letter}1";
$this->excel->getActiveSheet()->getStyle($header_range)->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle($header_range)->getFont()->setSize(16);
// Fetching the table data
$row = 2;
foreach($query->result() as $data){
$col = 0;
foreach ($fields as $field)
{
$this->excel->getActiveSheet()->setCellValueByColumnAndRow($col, $row,   $data->$field);
$col++;
}
$row++;
}
$this->excel->setActiveSheetIndex(0);
$filename=$yr.'taxPaymentReport.xlsx'; //Save The worksheet With This File Name
header('Content-Type: application/vnd.ms-excel'); //Mime Type For Excel2005
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0'); //no cache
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel2007');
$objWriter->save('php://output');

我已经尝试更改标题,看看我是否可以获得结果,但无济于事。有更好理解的人可以告诉我错误吗?

0 个答案:

没有答案
相关问题