This how look generated excel file: with the warning messages: Message: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? Filename: Shared/OLE.php
This is comes in excel file - þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ @€Åfôí Ö@€Åfôí ÖþÿÕÍÕœ.“—+,ù®0¼HPX`hp
I have tried with iconv(mb_detect_encoding($result, mb_detect_order(), true), "UTF-8", $result); coversion as well.
This is the code:
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;
}
In PHPExcel/Shared/OLE.php, function _readPpsWks($blockId)
, there is an error in the for / switch structure.
In the default case of the switch, you write continue;
. But this does NOT exit the for
loop. It only exits the "switch" structure, and continue under. You have to write: continue 2;
, at line number 290.
default:
continue 2;
Please try this, it might helps. This works for me.
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');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.