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

附錄
- 網(wǎng)上的經(jīng)驗(yàn),基本為 php iconv() : Detected an illegal character in input string, 測(cè)試發(fā)現(xiàn)都無(wú)法解決我的問(wèn)題
- 重點(diǎn)提示:當(dāng)前報(bào)錯(cuò),在
windows環(huán)境中,不會(huì)報(bào)錯(cuò),只有上傳到Linux服務(wù)器,才會(huì)有報(bào)錯(cuò)!
以上就是PHPExcel導(dǎo)出Excel報(bào)錯(cuò):PHPExcel_IOFactory::load()的解決方案的詳細(xì)內(nèi)容,更多關(guān)于PHPExcel導(dǎo)出Excel報(bào)錯(cuò)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
將FCKeditor導(dǎo)入PHP+SMARTY的實(shí)現(xiàn)方法
這篇文章主要介紹了將FCKeditor導(dǎo)入PHP+SMARTY的實(shí)現(xiàn)方法,涉及整合FCKeditor與SMARTY的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-01-01
php中通過(guò)正則表達(dá)式下載內(nèi)容中的遠(yuǎn)程圖片的函數(shù)代碼
下午抽空寫(xiě)了個(gè)用PHP正則表達(dá)式判斷內(nèi)容中的圖片,下載并保存非本域名下的圖片的程序2012-01-01
phpMyadmin 用戶權(quán)限中英對(duì)照
在登陸phpmyadmin時(shí)選擇了“中文 – Chinese Simplified“,那么就有中文的管理界面了,雖然在phpmyadmin中顯示的用戶權(quán)限顯示的還是英文的,但是鼠標(biāo)放上去時(shí),有中文的提示,這里把phpmyadmin v3.2.4中英文對(duì)照表附上2010-04-04
php中XMLHttpRequest(Ajax)不能設(shè)置自定義的Referer的解決方法
php中XMLHttpRequest(Ajax)不能設(shè)置自定義的Referer的解決方法,需要的朋友可以參考下。2011-11-11
Excel數(shù)據(jù)導(dǎo)入Mysql數(shù)據(jù)庫(kù)的實(shí)現(xiàn)代碼
當(dāng)配置好PHP運(yùn)行環(huán)境后,接下來(lái)我就開(kāi)始準(zhǔn)備數(shù)據(jù)源了,記得上次沒(méi)有講述Navicat的安裝方法,很簡(jiǎn)單,沒(méi)有什么特別的,一路Next就完畢了。2008-06-06

