Encoding issues for UTF8 CSV file when opening Excel and TextEdit

前端 未结 7 1878
余生分开走
余生分开走 2020-12-08 01:16

I recently added a CSV-download button that takes data from database (Postgres) an array from server (Ruby on Rails), and turns it into a CSV file on the client side (Javasc

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 01:33

    Excel likes Unicode in UTF-16 LE with BOM encoding. Output the correct BOM (FF FE), then convert all your data from UTF-8 to UTF-16 LE.

    Windows uses UTF-16 LE internally, so some applications work better with UTF-16 than with UTF-8.

    I haven't tried to do that in JS, but there're various scripts on the web to convert UTF-8 to UTF-16. Conversion between UTF variations is pretty easy and takes just a dozen of lines.

提交回复
热议问题