我使用PHPExcel导出我的MySQL数据ta xls文件,但是当我运行它时回显一些东西而不是将文件下载到我的本地 . 我在centos 7上使用firefox .
我的错误是这样的:
��ࡱ�;�� ?����@ABCDEFGHIJKL������������������������������������������������������������������������������������������������������������������������������������������������������������
这是我的代码:
foreach($this->items as $r => $dataRow) {
$row = $baseRow + $r;
$objPHPExcel->getActiveSheet()->insertNewRowBefore($row,1);
$objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $r+1)
->setCellValue('B'.$row, $dataRow['a'])
->setCellValue('C'.$row, $dataRow['b_display'])
->setCellValue('D'.$row, $dataRow['c_count'])
->setCellValue('E'.$row, $dataRow['d'])
->setCellValue('F'.$row, $dataRow['e'])
->setCellValue('G'.$row, '=C'.$row.'*D'.$row);
}
$filename=mt_rand(1,100000).'.xls'; //just some random filename
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition: attachment; filename=DoanhNghiep.xls");
header("Pragma: no-cache");
header("Expires: 0");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); //downloadable file is in Excel 2003 format (.xls)
$objWriter->save('php://output'); //send it to user, of course you can save it to disk also!
exit;
有人可以帮帮我吗?读书!
1 回答
或者您也可以尝试在我的项目中为我工作的代码