Javascript to csv export encoding issue

前端 未结 8 1360
Happy的楠姐
Happy的楠姐 2020-11-29 00:33

I need to export javascript array to excel file and download it I\'m doing it in this code. data is a javascript object array.

var csvContent = \"data:t         


        
8条回答
  •  自闭症患者
    2020-11-29 01:04

    To export CSV containing multibyte characters and make it readable on text editor and Excel in multiple OS platforms (Windows, Linux, MacOS), the following rules should be applied:

    1. Separate the field with tab instead of comma (so that Excel on MacOS can properly display the generated CSV file)
    2. Encode the string / content with UTF-16 little endian (UTF16-LE) instead of UTF-8
    3. Add byte order mark (BOM) 0xFEFF as specified in RFC2781 section 3.2 at the beginning of the serialized stream to explicitly provide "signature" of content encoded with UTF16-LE

    Further elaboration, use cases and sample code with NodeJS can be seen in this article.

提交回复
热议问题