2009-12-23 18 views
1

我有幾個導出到Excel的報告。問題是徘徊無論有特殊字符,它是由一些有趣的符號將特殊字符寫入Excel的問題

例如,替換成「 - 」(連字符)被A代替€「......

任何有助於解決問題? ?

+0

請輸入密碼?沒有代碼,任何人都很難理解手頭的問題。 – shahkalpesh 2009-12-23 14:02:34

+0

我懷疑這是因爲Excel不會處理UTF-8。嘗試在創建Excel工作表時將字符串編碼爲例如latin1。 – 2009-12-23 14:14:33

回答

0

最直接的辦法就是編碼的文本文件爲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); 
      } 
     } 
    } 
} 
0

這是代碼 - view at PasteBin

+0

什麼是您的web.config中的請求/響應編碼? – 2009-12-25 23:08:30