Search code examples
laravelutf-8character-encodingexport-to-csvshift-jis

Laravel export csv file with 'use_bom'=>true can't render text with correct encode


I use 'use_bom' => true to read Japanese in CSV files when opening with Excel. I call through postman everything is fine, but when I call the API via FE, I get a Japanese font error.

I tried changing the content-type content-encode in the header, but it doesn't seem to work.


Solution

  • I tried searching with the keyword "bomb csv" and I did the following

    • before

      href={data:text/csv;charset=utf-8,${encodeURIComponent(dataCSV,)}}

    • after

      href={data:text/csv;charset=utf-8,${encodeURIComponent('\uFEFF' + dataCSV,)}}

    so the returned csv file does not have font errors anymore. I don't understand why but glad I fixed it anyway