[php]代码库
php 导出页面,不能输出任何其他信息,不能echo print var_dump等,否则,导出EXCEL,,显示无法打开
$this->load->library("PHPExcel");
$resultPHPExcel = new PHPExcel();
$resultPHPExcel->getActiveSheet()->setCellValue('A1', '季度');
$resultPHPExcel->getActiveSheet()->setCellValue('B1', '名称');
$resultPHPExcel->getActiveSheet()->setCellValue('C1', '数量');
$resultPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15); //设置宽度
$resultPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(35);
$resultPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
$resultPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
$i = 2;
for($j=0;$j<5;$j++){
$resultPHPExcel->getActiveSheet()->setCellValue('A' . $i, $j);
$resultPHPExcel->getActiveSheet()->setCellValue('B' . $i, $j);
$resultPHPExcel->getActiveSheet()->setCellValue('C' . $i, $j);
$i ++;
}
$title = "报名概况表";
$resultPHPExcel->getActiveSheet()->setTitle( $title );
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$resultPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$title.'.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($resultPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
//设置字段类型
$resultPHPExcel->getActiveSheet()->setCellValueExplicit('C'.$i,$v['z']['shenfenhao'],PHPExcel_Cell_DataType::TYPE_STRING);
$resultPHPExcel->getActiveSheet()->getStyle('C'.$i)->getNumberFormat()->setFormatCode("@");