背景
- 近期在做 excel文件数据导出时,遇到如下报错:
iconv(): detected an illegal character in input string
- 场景:计划任务后台,分步导出 大数据 excel文件
- 发现在加载文件时,会有报错
报错信息 如下:
{ "name": "php notice", "message": "iconv(): detected an illegal character in input string", "code": 8, "type": "yii\\base\\errorexception", "file": "/usr/share/nginx/html/ycsh_automat/classes/phpexcel/shared/string.php", "line": 490, "stack-trace": [ "#0 [internal function]: yii\\base\\errorhandler->handleerror(8, 'iconv(): detect...', '/usr/share/ngin...', 493, array)", "#1 /usr/share/nginx/html/ycsh_automat/classes/phpexcel/shared/string.php(490): iconv('cp1252', 'utf-8', '\\xe8\\xae\\xa2\\xe5\\x8d\\x95\\xe5\\x88\\x97\\xe8\\xa1\\xa8\\x00\\x00\\x00...')", "#2 /usr/share/nginx/html/ycsh_automat/classes/phpexcel/reader/excel5.php(1362): phpexcel_shared_string::convertencoding('\\xe8\\xae\\xa2\\xe5\\x8d\\x95\\xe5\\x88\\x97\\xe8\\xa1\\xa8\\x00\\x00\\x00...', 'utf-8', 'cp1252')", "#3 /usr/share/nginx/html/ycsh_automat/classes/phpexcel/reader/excel5.php(633): phpexcel_reader_excel5->readsummaryinformation()", "#4 /usr/share/nginx/html/ycsh_automat/classes/phpexcel/iofactory.php(192): phpexcel_reader_excel5->load('/usr/share/ngin...')", "#5 /usr/share/nginx/html/ycsh_automat/common/services/excelmzservice.php(154): phpexcel_iofactory::load('/usr/share/ngin...')", "#6 /usr/share/nginx/html/ycsh_automat/common/models/exporttask.php(306): common\\services\\excelmzservice->croncreateexportfile(array, array, '/usr/share/ngin...', array, '\\xe8\\xae\\xa2\\xe5\\x8d\\x95\\xe5\\x88\\x97\\xe8\\xa1\\xa8')", "#7 /usr/share/nginx/html/ycsh_automat/api/controllers/croncontroller.php(54): common\\models\\exporttask::execexporttask(object(common\\models\\exporttask), 1, '{\"search_params...')", "#8 [internal function]: api\\controllers\\croncontroller->actionrunexporttask()", ... }
问题分析
- 根据详细报错信息,可以知道,是执行 phpexcel_iofactory::load() 方法时,因为文件名编码问题造成程序中断
- 业务场景中,即在分步追加 excel文件数据,加载文件名时,识别转码有误
- 继而定位到 classes\phpexcel\shared\string.php 的 convertencoding() 方法的的第一个条件判断不满足
解决方案
修改文件 classes\phpexcel\shared\string.php
的 convertencoding()
方法的的第一个条件判断,如下
附录
- 网上的经验,基本为 php iconv() : detected an illegal character in input string, 测试发现都无法解决我的问题
- 重点提示:当前报错,在
windows
环境中,不会报错,只有上传到linux
服务器,才会有报错!
以上就是phpexcel导出excel报错:phpexcel_iofactory::load()的解决方案的详细内容,更多关于phpexcel导出excel报错的资料请关注代码网其它相关文章!
发表评论