向Excel写入特殊字符

我有几个导出到Excel的报告。 问题是哪里有特殊的字符,它正在被一些有趣的符号取代

例如,' – '(连字符)被replace为…

任何帮助解决问题?

最直接的方法是将文本文件编码为UTF-8。 我运行下面的代码,在Excel 2007中打开生成的hyphen.txt文件,它按预期工作:

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var hyphen = "\u2010\r\n"; var encoding = Encoding.UTF8; var bytes = encoding.GetBytes(hyphen); using (var stream = new System.IO.FileStream(@"c:\tmp\hyphen.txt", System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite)) { stream.Write(bytes, 0, bytes.Length); } } } } 

这是在PasteBin的代码 – 视图 。