您好,登錄后才能下訂單哦!
這篇文章主要介紹了php導(dǎo)出excel出現(xiàn)亂碼的解決方法,具有一定借鑒價(jià)值,需要的朋友可以參考下。希望大家閱讀完這篇文章后大有收獲。下面讓小編帶著大家一起了解一下。
php導(dǎo)出excel出現(xiàn)亂碼的解決方法:在處理完數(shù)據(jù)之后,輸出excel文件之前,利用ob_end_clean()函數(shù)清空緩沖區(qū)并關(guān)閉輸出緩沖即可。
解決方法:
在處理完數(shù)據(jù)之后,輸出excel文件之前利用 ob_end_clean() 函數(shù)進(jìn)行處理。
ob_end_clean清空(擦除)緩沖區(qū)并關(guān)閉輸出緩沖。成功時(shí)返回 TRUE, 或者在失敗時(shí)返回 FALSE。
部分代碼如下:
foreach ($licenseList as $key => $item) { $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A' . ($key + 2), $item["company_name"]) ->setCellValue('B' . ($key + 2), $item["user_name"]) ->setCellValue('C' . ($key + 2), $item["order_number"]) ->setCellValue('D' . ($key + 2), $item['apply_type']==2 ? 'official':'trial') ->setCellValue('E' . ($key + 2), $item["license_key"]) ->setCellValue('F' . ($key + 2), $statusArr[$item['license_status']])->setCellValue('G' . ($key + 2), $item["user_email"]) ->setCellValue('H' . ($key + 2), date('y/m/d H:i:s', strtotime($item['insert_time']))); } $objPHPExcel->getActiveSheet()->setTitle('Simple'); $objPHPExcel->setActiveSheetIndex(0); ob_end_clean();//解決亂碼核心 就在此處添加此函數(shù) header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="test_list.xls"'); header('Cache-Control: max-age=0'); header('Cache-Control: max-age=1'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: cache, must-revalidate'); header('Pragma: public'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit;
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享php導(dǎo)出excel出現(xiàn)亂碼的解決方法內(nèi)容對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,遇到問(wèn)題就找億速云,詳細(xì)的解決方法等著你來(lái)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。