将数据从数据库导出到excel文件时出现问题。我正在使用CodeIgniter和库PHPExcel。
public function export(){
$ambildata = $this->model_kelola->read(NULL,NULL,'market','result',NULL,NULL);
if(count($ambildata )>0){
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Administrator")->setTitle("Data Quotation Prices");
$objset = $objPHPExcel->setActiveSheetIndex(0);
$objget = $objPHPExcel->getActiveSheet();
$objget->setTitle('Sample Sheet');
$objget->getStyle("A1:C1")->applyFromArray(
array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => '92d050')
),
'font' => array(
'color' => array('rgb' => '000000')
)
)
);
$cols = array("A","B","C");
$val = array("Market Series ","Market Coupon","Market Maturity");
for ($a=0;$a<3; $a++) {
$objset->setCellValue($cols[$a].'1', $val[$a]);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
$style = array(
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
)
);
$objPHPExcel->getActiveSheet()->getStyle($cols[$a].'1')->applyFromArray($style);
}
$baris = 2;
foreach ($ambildata as $frow){
$objset->setCellValue("A".$baris, $frow->market_series);
$objset->setCellValue("B".$baris, $frow->market_coupon);
$objset->setCellValue("C".$baris, $frow->market_maturity);
$objPHPExcel->getActiveSheet()->getStyle('C1:C'.$baris)->getNumberFormat()->setFormatCode('0');
$baris++;
}
$objPHPExcel->getActiveSheet()->setTitle('Data Export');
$objPHPExcel->setActiveSheetIndex(0);
$filename = urlencode("Data".date("Y-m-d H:i:s").".xls");
header('Content-Type: application/xlx');
header('Content-Disposition: attachment;filename="'.$filename.'"');
$objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}
else{
redirect('Excel');
}
}
这是我的错误
当试试print_r(get_defined_vars())时,生成如下消息:
你能告诉我哪里错了吗?