Jon
Jon

Reputation: 866

Problems with foreign language encoding in CSV in Visual Basic

I have a VB.Net script saving a CSV from a database which contains Japanese, Chinese, Korean, and English characters.

The file opens fine in a plain text editor, but in Excel it shows either the "question mark" character, other apparently randomly characters, or dashes. It does this no matter which encoding format I choose when importing the data.

The code I have to open the file looks like this

  Response.ContentType = "text/csv"
  Response.AddHeader("Content-Disposition", "attachment; filename=notifications.csv")
  Dim utf8 As New UTF8Encoding()
  Dim strW As New IO.StreamWriter("\windows\temp\notifications.csv", False, utf8)
  strW.Write(utf8.GetPreamble())

*EDIT: * Apparently this only happens in Excel 2011 for Mac

Upvotes: 1

Views: 1458

Answers (1)

Konrad Rudolph
Konrad Rudolph

Reputation: 545588

Excel on Mac has severe deficiencies in this department. CSV files are assumed to be encoded in MacRoman – any encoding preamble is simply ignored. As far as I’m aware there’s no workaround for this, you have to encode the CSV file accordingly, or use the file open dialog in Excel to select the appropriate encoding.

Upvotes: 1

Related Questions