PHPExcel導(dǎo)出Excel報錯:PHPExcel_IOFactory::load()的解決方案
背景
- 近期在做 excel文件數(shù)據(jù)導(dǎo)出時,遇到如下報錯:
iconv(): Detected an illegal character in input string - 場景:計劃任務(wù)后臺,分步導(dǎo)出 大數(shù)據(jù) excel文件
- 發(fā)現(xiàn)在加載文件時,會有報錯
報錯信息 如下:
{
"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()",
...
}
問題分析
- 根據(jù)詳細報錯信息,可以知道,是執(zhí)行 PHPExcel_IOFactory::load() 方法時,因為文件名編碼問題造成程序中斷
- 業(yè)務(wù)場景中,即在分步追加 excel文件數(shù)據(jù),加載文件名時,識別轉(zhuǎn)碼有誤
- 繼而定位到 Classes\PHPExcel\Shared\String.php 的 ConvertEncoding() 方法的的第一個條件判斷不滿足
解決方案
修改文件 Classes\PHPExcel\Shared\String.php 的 ConvertEncoding() 方法的的第一個條件判斷,如下

附錄
- 網(wǎng)上的經(jīng)驗,基本為 php iconv() : Detected an illegal character in input string, 測試發(fā)現(xiàn)都無法解決我的問題
- 重點提示:當(dāng)前報錯,在
windows環(huán)境中,不會報錯,只有上傳到Linux服務(wù)器,才會有報錯!
以上就是PHPExcel導(dǎo)出Excel報錯:PHPExcel_IOFactory::load()的解決方案的詳細內(nèi)容,更多關(guān)于PHPExcel導(dǎo)出Excel報錯的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
將FCKeditor導(dǎo)入PHP+SMARTY的實現(xiàn)方法
這篇文章主要介紹了將FCKeditor導(dǎo)入PHP+SMARTY的實現(xiàn)方法,涉及整合FCKeditor與SMARTY的技巧,非常具有實用價值,需要的朋友可以參考下2015-01-01
php中通過正則表達式下載內(nèi)容中的遠程圖片的函數(shù)代碼
下午抽空寫了個用PHP正則表達式判斷內(nèi)容中的圖片,下載并保存非本域名下的圖片的程序2012-01-01
php中XMLHttpRequest(Ajax)不能設(shè)置自定義的Referer的解決方法
php中XMLHttpRequest(Ajax)不能設(shè)置自定義的Referer的解決方法,需要的朋友可以參考下。2011-11-11
Excel數(shù)據(jù)導(dǎo)入Mysql數(shù)據(jù)庫的實現(xiàn)代碼
當(dāng)配置好PHP運行環(huán)境后,接下來我就開始準備數(shù)據(jù)源了,記得上次沒有講述Navicat的安裝方法,很簡單,沒有什么特別的,一路Next就完畢了。2008-06-06

