1

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;

} 
5
  • 3
    The last version of PHPExcel was released in 2015 and it is now marked as dead. You are instead encouraged to used the replacement, PhpSpreadsheet, which I would also strongly recommend. In PHP 7.3, a special warning was added to switch statements which is what you are seeing. There are not plans by the author to fix this, so your only alternative would be to fork the code and fix things on your own. Commented May 15, 2020 at 18:06
  • Also, the message about continue is a warning, not an error. Is there something else breaking? If so, please describe. Commented May 15, 2020 at 18:28
  • 1
    @thelr excel file comes with Unicode characters Commented May 18, 2020 at 4:21
  • Got it. is there an error printed when PHP gets to the unicode? Usually it would be prefixed by "Fatal Error". Commented May 18, 2020 at 11:55
  • I solved issue by using PhpSpreadsheet and there also I face Unicode problem so this two lines of code before and after write solved unicode problem: ob_end_clean(); $writer->save('php://output'); exit(); Commented May 21, 2020 at 6:40

2 Answers 2

1

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;
Sign up to request clarification or add additional context in comments.

Comments

0

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');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.