当前位置: 代码网 > it编程>编程语言>Php > PHPExcel导出Excel报错:PHPExcel_IOFactory::load()的解决方案

PHPExcel导出Excel报错:PHPExcel_IOFactory::load()的解决方案

2024年05月18日 Php 我要评论
背景近期在做 excel文件数据导出时,遇到如下报错:iconv(): detected an illegal character in input string场景:计划任务后台,分步导出 大数据

背景

  • 近期在做 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() 方法的的第一个条件判断,如下

附录

以上就是phpexcel导出excel报错:phpexcel_iofactory::load()的解决方案的详细内容,更多关于phpexcel导出excel报错的资料请关注代码网其它相关文章!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com