Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用phpExcel在php codeigniter中打开生成的excel文件时出错_Php_Codeigniter_Phpexcel - Fatal编程技术网

使用phpExcel在php codeigniter中打开生成的excel文件时出错

使用phpExcel在php codeigniter中打开生成的excel文件时出错,php,codeigniter,phpexcel,Php,Codeigniter,Phpexcel,生成的excel文件的外观如下: 警告信息如下: 消息:“继续”目标开关相当于“断开”。你想用“继续2”吗? 文件名:Shared/OLE.php 这是excel文件- þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

生成的excel文件的外观如下: 警告信息如下: 消息:“继续”目标开关相当于“断开”。你想用“继续2”吗? 文件名:Shared/OLE.php

这是excel文件- þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ @-+,0¼HPX`hp

我已经尝试过iconv(mb_detect_encoding($result,mb_detect_order(),true),“UTF-8”,以及$result);conversion

代码如下:

 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;

} 

请试试这个,它可能会有帮助。这个对我有用

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

请试试这个,它可能会有帮助。这个对我有用

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

的上一个版本于2015年发布,现在被标记为已死亡。我们鼓励您使用替换版本,我也强烈建议您使用。在PHP 7.3中,您看到的
switch
语句中添加了一个特殊警告。作者没有计划修复此问题,因此您唯一的选择是o自行编写代码并修复问题。此外,关于
continue
的消息是一个警告,而不是一个错误。是否还有其他问题?如果是,请描述。@excel文件带有Unicode字符。PHP使用Unicode时是否会打印错误?通常会以“致命错误”作为前缀。我通过使用PHPSReadSheet解决了这个问题,在那里我还面临Unicode问题,所以写之前和之后的两行代码解决了Unicode问题:ob_end_clean();$writer->save()php://output“);退出();的上一个版本于2015年发布,现在被标记为已死亡。我们鼓励您使用替换版本,我也强烈建议您使用。在PHP 7.3中,您看到的
switch
语句中添加了一个特殊警告。作者没有计划修复此问题,因此您唯一的选择是您可以自己编写代码并修复问题。另外,关于
continue
的消息是一个警告,而不是一个错误。是否还有其他问题?如果有,请描述。@thelr excel文件带有Unicode字符。当PHP使用Unicode时是否会打印错误?通常会以“致命错误”作为前缀。我通过使用PHPSReadSheet解决了这个问题,在那里我还面临Unicode问题,所以写之前和之后的两行代码解决了Unicode问题:ob_end_clean();$writer->save()php://output”);退出();