laravel-excel3.1 設(shè)置CSV文件編碼格式

laravel-excel3.1文件導(dǎo)入CSV格式獲取不到中文,是因?yàn)閏sv文件編碼一般為GBK,而3.1讀取的編碼格式并不是BGK,導(dǎo)致CSV讀取不到中文或亂碼。

<?php

namespace App\Imports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithCustomCsvSettings; // 設(shè)置csv文件編碼

class ImportExcel implements ToCollection, WithCustomCsvSettings
{
    /**
     * @param Collection $collection
     */
    public function collection(Collection $collection)
    {
        //
    }
    
    public function getCsvSettings(): array
    {
        return [
            'input_encoding' => 'GBK' // 設(shè)置編碼為GBK格式
        ];
    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容