1

I have this code:

StringBuilder output = new StringBuilder();

output.AppendLine("Saldo a disposición: 23.15€");

[...]

System.Text.UnicodeEncoding en = new UnicodeEncoding();
byte[] byteArray = en.GetBytes(output.ToString());
MemoryStream stream = new MemoryStream(byteArray);
string filename = Guid.NewGuid().ToString("N").ToUpper() + ".csv";

stream.Flush();
stream.Seek(0, SeekOrigin.Begin);
return new FileStreamResult(stream, "application/vnd.ms-excel") { FileDownloadName = filename};

When I open the document the symbol "€" and the accent in "disposión" don't appears. It seems like that:

Saldo a disposici�n: 23.15�

Does anyone tell me how to do this?

Thank you!!

4

1 回答 1

1

以下对我有用:

string filename = Guid.NewGuid().ToString("N").ToUpper() + ".csv";

MemoryStream stream = new MemoryStream();

StreamWriter output = new StreamWriter(stream, Encoding.UTF8, 2 << 22);
output.WriteLine("Column1,Column2");
output.WriteLine("value for column one,\"Saldo a disposición: 23.15€\"");
output.WriteLine("another row col 1,another row col 2");
output.Flush();

stream.Seek(0, SeekOrigin.Begin);

return new FileStreamResult(stream, "application/octet-stream") { FileDownloadName = filename };

似乎是编码。

http://en.wikipedia.org/wiki/Unicode http://en.wikipedia.org/wiki/UTF-8

于 2013-05-14T13:19:38.987 回答