Note that there are some explanatory texts on larger screens.

plurals
  1. POc#, Excel + csv: how to get the correct encoding?
    text
    copied!<p>I've been trying this for quite a while now, but can't figure it out. I'm trying to export data to Excel via a *.csv file. It works great so far, but I have some encoding problems when opening the files in Excel.</p> <p>(original string on the left, EXCEL result on the right): </p> <pre><code>Messwert(µm / m) ==&gt; Messwert(µm / m) Dümme Mässöng ==&gt; Dümme Mässöng </code></pre> <p>Notepad++ tells me that the file is encoded "ANSI as UTF8"(WTF?) </p> <p>So here are different ways I tried to get a valid result: obvious implementation: </p> <pre><code>tWriter.Write(";Messwert(µm /m)"); </code></pre> <p>more sophisticated one (tried probably a dozen or more encoding combinations:)</p> <pre><code>tWriter.Write(Encoding.Default.GetString(Encoding.Unicode.GetBytes(";Messwert(µm /m)"))); tWriter.Write(Encoding.ASCII.GetString(Encoding.Unicode.GetBytes(";Messwert(µm /m)"))); </code></pre> <p>and so on</p> <p>Whole source code for the method creating the data:</p> <pre><code> MemoryStream tStream = new MemoryStream(); StreamWriter tWriter = new StreamWriter(tStream); tWriter.Write("\uFEFF"); tWriter.WriteLine(string.Format("{0}", aMeasurement.Name)); tWriter.WriteLine(aMeasurement.Comment); tWriter.WriteLine(); tWriter.WriteLine("Zeit in Minuten;Messwert(µm / m)"); TimeSpan tSpan; foreach (IMeasuringPoint tPoint in aMeasurement) { tSpan = new TimeSpan(tPoint.Time - aMeasurement[0].Time); tWriter.WriteLine(string.Format("{0};{1};", (int)tSpan.TotalMinutes, getMPString(tPoint))); } tWriter.Flush(); return tStream; </code></pre> <p>Generated CSV file:</p> <pre><code>Dümme Mössäng Testmessung die erste Zeit in Minuten;Messwert(µm / m) 0;-703; 0;-381; 1;1039; 1;1045; 2;1457; 2;1045; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload