使用 phpExcel 在 php 代码点火器中打开生成的 excel 文件时出错



这个如何看起来生成的excel文件: 带有警告消息: 消息:"继续"定位开关等同于"中断"。你的意思是使用"继续2"吗? 文件名:共享/OLE.php

这是在excel文件中 - þÿÿÿÿ×ÿ×ÿí ÿÿÿ×É×É×ÿ×ÿÊÿ @€åfôí Ö@€åfôíöþÿõíõœ."—+,ù®01/4HPX'hp

我尝试过使用iconv(mb_detect_encoding($result,mb_detect_order((,true(,"UTF-8",$result(;也尝试过。

这是代码:

public function exportExcel() {
$this->load->library('excel');
$registrationIDArr = $_POST["registrationID"];
$resigtrationIDStr = implode(",",$registrationIDArr);
$currDate = date("d-m-Y_H_i");
$file = 'VolunteerRegistration_'.$currDate.'.xls';
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle('Volunteer Details');
$style = array('font' => array('size' => 12,'bold' => true));
$objPHPExcel->getActiveSheet()->getStyle('A1:B1')->applyFromArray($style);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Name');
$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Email');
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
$rows = 2;
$result = $this->getVolunteerDetailsForExcelExport($resigtrationIDStr);
foreach($result as $row){ 
$objPHPExcel->getActiveSheet()->setCellValue('A'.$rows, $row->name);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$rows, $row->email);
$rows++;  
}

header('Content-Type: application/vnd.ms-excel; charset=UTF-8');
header('Content-Disposition: attachment; filename="'.$file.'"');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

ob_end_clean();
ob_start();
$objWriter->save('php://output');
exit;
}
public function getVolunteerDetailsForExcelExport($registrationIDStr){
$this->db->select("CONCAT(fname,' ',mname,' ',lname) AS name, email");
$this->db->from('UserRegistration');
$wherelist = "id in($registrationIDStr)";
$this->db->where($wherelist);
$query= $this->db->get();
$result = $query->result();
return $result;
} 

在 PHPExcel/Shared/OLE.php 中,function _readPpsWks($blockId)中存在错误/switch 结构.
在开关的默认情况下,你写continue;。但这不会退出for循环。它只退出"开关"结构,并继续。你必须写:continue 2;,在第290行。

default:
continue 2;

请尝试此操作,可能会有所帮助。这对我有用。

require 'PHPExcel.php';
$objPHPExcel = new PHPExcel();
/*CODE for excel*/
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="file.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');

相关内容

  • 没有找到相关文章

最新更新