简体   繁体   English

PHPExcel未知字符

[英]PHPExcel unknown characters

I've followed some tutorials and saw some people with same issue but I can't figure out how to put this working on my project. 我已经看了一些教程,看到了一些有同样问题的人,但是我不知道如何将其用于我的项目。

Btw, I'm using CodeIgniter framework and I have Excel 2007 in my computer. 顺便说一句,我正在使用CodeIgniter框架,并且我的计算机中装有Excel 2007。

public function exportExcel(){

    require(APPPATH . 'libraries/toExcel/PHPExcel.php');
    $objPHPExcel = new PHPExcel();

    $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue('A1', 'Hello');

    // Rename worksheet
    $objPHPExcel->getActiveSheet()->setTitle('Simple');     

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

    header('Content-Type: application/vnd.ms-excel; charset=utf-8');
    header('Content-Disposition: attachment; filename=01simple.xls');
    header('Cache-Control: max-age=0');

    $objWriter->save('php://output');

    exit;
}

This is my code just for testings. 这是我的代码,仅用于测试。 Whenever I download the file generated by that function and try to open it is this what I get: 每当我下载该函数生成的文件并尝试打开它时,这就是我得到的: 在此处输入图片说明

And when I click "Yes" I receive this: 当我单击“是”时,我收到以下消息:

在此处输入图片说明

Solved. 解决了。

ob_end_clean();
ob_start();
$objWriter->save('php://output');

All php_excel changed Unknown Creator worksheet. 所有php_excel更改了Unknown Creator工作表。 directory application/third_party/phpexcel/PHPExcel/DocumentProperties.php changed line 43; 目录application / third_party / phpexcel / PHPExcel / DocumentProperties.php更改了第43行;

private $creator = 'Unknown Creator'; changed ↓
private $creator = 'your name';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM