PhpExcel类,在windows系统下能导出Excel文件,但是在linux下就不行,怎么回事?
这是导出的界面以下是代码://导出Excelif($_POST['file_format']=="excel"){//导出excelVendor("PHPExcel.IO...
这是导出的界面
以下是代码:
//导出Excel if($_POST['file_format']=="excel"){ //导出excel Vendor("PHPExcel.IOFactory"); $objectPHPExcel = new PHPExcel(); $objectPHPExcel->setActiveSheetIndex(0);
.......... ->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); ............ //设置居中 $objectPHPExcel->getActiveSheet()->getStyle('B2:L2') ->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $n = 0; foreach ($AppointmentDataAll as $key=>$ticket) { //转换性别 $objectPHPExcel->getActiveSheet()->setCellValue('A'.($n+3) ,$ticket['userCompany']); ...... //设置单元格为text属性 $objectPHPExcel->getActiveSheet()->setCellValueExplicit('F'.($n+3),$ticket['u_card'],PHPExcel_Cell_DataType::TYPE_STRING); $objectPHPExcel->getActiveSheet()->getStyle('F'.($n+3))->getNumberFormat()->setFormatCode("@"); $objectPHPExcel->getActiveSheet()->setCellValue('G'.($n+3) ,$ticket['userWedlockDict']); $objectPHPExcel->getActiveSheet()->setCellValue('H'.($n+3) ,$ticket['centerName']); //公司名称 $objectPHPExcel->getActiveSheet()->setCellValue('M'.($n+3) ,$ticket['appointment_status']); $n++; } //设置颜色 $objectPHPExcel->getActiveSheet()->getStyle('A1:L1')->getFill() ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF66CCCC'); $objWriter = new PHPExcel_Writer_Excel2007($objectPHPExcel); $objectPHPExcel->getActiveSheet()->setTitle('订单汇总表'); ob_end_clean();//清除缓冲区,避免乱码 header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="订单汇总表(' . date('Ymd-His') . ').xls"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objectPHPExcel, 'Excel5'); //避免乱码 $objWriter->save('php://output'); } 展开
以下是代码:
//导出Excel if($_POST['file_format']=="excel"){ //导出excel Vendor("PHPExcel.IOFactory"); $objectPHPExcel = new PHPExcel(); $objectPHPExcel->setActiveSheetIndex(0);
.......... ->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); ............ //设置居中 $objectPHPExcel->getActiveSheet()->getStyle('B2:L2') ->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $n = 0; foreach ($AppointmentDataAll as $key=>$ticket) { //转换性别 $objectPHPExcel->getActiveSheet()->setCellValue('A'.($n+3) ,$ticket['userCompany']); ...... //设置单元格为text属性 $objectPHPExcel->getActiveSheet()->setCellValueExplicit('F'.($n+3),$ticket['u_card'],PHPExcel_Cell_DataType::TYPE_STRING); $objectPHPExcel->getActiveSheet()->getStyle('F'.($n+3))->getNumberFormat()->setFormatCode("@"); $objectPHPExcel->getActiveSheet()->setCellValue('G'.($n+3) ,$ticket['userWedlockDict']); $objectPHPExcel->getActiveSheet()->setCellValue('H'.($n+3) ,$ticket['centerName']); //公司名称 $objectPHPExcel->getActiveSheet()->setCellValue('M'.($n+3) ,$ticket['appointment_status']); $n++; } //设置颜色 $objectPHPExcel->getActiveSheet()->getStyle('A1:L1')->getFill() ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF66CCCC'); $objWriter = new PHPExcel_Writer_Excel2007($objectPHPExcel); $objectPHPExcel->getActiveSheet()->setTitle('订单汇总表'); ob_end_clean();//清除缓冲区,避免乱码 header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="订单汇总表(' . date('Ymd-His') . ').xls"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objectPHPExcel, 'Excel5'); //避免乱码 $objWriter->save('php://output'); } 展开
2个回答
展开全部
代码没看,但想说一定是你的路径设置有问题,linux严格区分url的大小写
追问
我找到原因了
ob_end_clean();
是这个函数导致的问题
这个函数作用是清除缓冲区,避免乱码
但是在linux下就会导致Excel导出不成功
把这代码注释就好了
我也不知道什么原因
追答
soga
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询