[英]Error while opening generated excel file in php codeigniter using phpExcel
這看起來如何生成 excel 文件:帶有警告消息:消息:“繼續”目標開關相當於“中斷”。 您是要使用“繼續 2”嗎? 文件名:共享/OLE.php
This is comes in excel file - þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ @€Åfôí Ö@€Åfôí ÖþÿÕÍÕœ.“—+,ù®0¼HPX`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)
中,for / switch 結構有錯誤。
在 switch 的默認情況下,你寫continue;
. 但這不會退出for
循環。 它只退出“switch”結構,繼續下。 你必須寫: 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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.