Is it possible to force Excel recognize UTF-8 CSV files automatically?

后端 未结 27 1647
醉梦人生
醉梦人生 2020-11-21 22:27

I\'m developing a part of an application that\'s responsible for exporting some data into CSV files. The application always uses UTF-8 because of its multilingual nature at

相关标签:
27条回答
  • 2020-11-21 22:56

    This is my working solution:

    vbFILEOPEN = "your_utf8_file.csv"
    Workbooks.OpenText Filename:=vbFILEOPEN, DataType:=xlDelimited, Semicolon:=True, Local:=True, Origin:=65001
    

    The key is Origin:=65001

    0 讨论(0)
  • 2020-11-21 22:56
    1. Download & install LibreOffice Calc
    2. Open the csv file of your choice in LibreOffice Calc
    3. Thank the heavens that an import text wizard shows up...
    4. ...select your delimiter and character encoding options
    5. Select the resulting data in Calc and copy paste to Excel
    0 讨论(0)
  • 2020-11-21 22:58

    If you want to make it fully automatic, one click, or to load automatically into Excel from say a web page, but can't generate proper Excel files, then I would suggest looking at SYLK format as an alternative. OK it is not as simple as CSV but it is text based and very easy to implement and it supports UTF-8 with no issues.

    I wrote a PHP class that receives the data and outputs a SYLK file which will open directly in Excel by just clicking the file (or will auto-launch Excel if you write the file to a web page with the correct mime type. You can even add formatting (like bold, format numbers in particular ways etc) and change column sizes, or auto size columns to the text in the columns and all in all the code is probably not more than about 100 lines.

    It is dead easy to reverse engineer SYLK by creating a simple spreadsheet and saving as SYLK and then reading it with a text editor. The first block are headers and standard number formats that you will recognise (which you just regurgitate in every file you create), then the data is simply an X/Y coordinate and a value.

    0 讨论(0)
  • 2020-11-21 22:59

    Yes it is possible. When writing the stream creating the csv, the first thing to do is this:

    myStream.Write(Encoding.UTF8.GetPreamble(), 0, Encoding.UTF8.GetPreamble().Length)
    
    0 讨论(0)
  • 2020-11-21 22:59

    First save the Excel spreadsheet as Unicode text. Open the TXT file using Internet explorer and click "Save as" TXT Encoding - choose the appropriate encoding, i.e. for Win Cyrillic 1251

    0 讨论(0)
  • 2020-11-21 23:00

    I tried everything I could find on this thread and similar, nothing worked fully. However, importing to google sheets and simply downloading as csv worked like a charm. Try it out if you come to my frustration point.

    0 讨论(0)
提交回复
热议问题