c#, Excel + csv: how to get the correct encoding? -


I'm trying this for a little while, but I can not understand it. I am trying to export the data to Excel via * .csv file. It works so far, but I have some encoding problems when opening files in Excel

(the left side is the original String, the result on Excel right) is:.

  Masswit (microgram / m) ==> Meswarts (micr / m) dumé masong == & gt; Dümme Mässèng  

Notepad ++ tells me that the file "ANSI" encoding as UTF8 (WTF?)

here in different ways I'm trying to get a valid result: Clear implementation:

  tWriter.Write ("Messwert (μm / m)");  
  tWriter.Write (Encoding.Default.GetString (Encoding.Unicode.GetBytes:  

and more sophisticated one (maybe a dozen or more encoding combinations Tried ("; masvirt (microg / m)"))); TWriter.Write (encoding.assici.getstring (encoding.uncodegatebytes ("; masvrat (microg / m)")));

and so on

The entire source code to create the method data:

  MemoryStream tStream = new MemoryStream (); Streamer trrr = new streamer (tstream); TWriter.Write ("\ uFEFF"); TWriter.WriteLine (string.Format ("{0}", aMeasurement.Name)); TWriter.WriteLine (aMeasurement.Comment); TWriter.WriteLine (); TWriter.WriteLine ("Jute in Minute; Mesverwutt (Microg / M)"); Timespan TSAPAN; Forex Currency (IMAGEPoint Note in One Measurement) {TSN = New TimeSpain (TPITETEM - AMAGEMENT [0]. Time); TWriter.WriteLine (string.Format ("{0}; {1};", (integer) TSNA extra minutes, getMPString (tPoint)); } TWriter.Flush (); Return TSTrim;  

Generated CSV file:

  Tested in Erst Zeta in Minuten; Messwert (μm / meter) 0; -703; 0; -381; 1; 1039; 1; 1045; 2; 1457; 2; 1045; Text after " 

It has been written as a fine for a Java application but in you You should be able to see something similar in C # You can also view documentation in class, in comments related to the byte order mark (BOM).


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -