我有這樣的代碼:如何編碼CSV文件導入?
string ABSfilePath = "";
CsvFileReader reader = null;
ABSfilePath = Server.MapPath("/myfile.csv");
try
{
reader = new CsvFileReader(ABSfilePath);
CsvRow myRow = new CsvRow();
while (reader.ReadRow(myRow))
{
Response.Write(myRow[0].ToString()+"<br />");
}
}
catch (Exception err)
{
Response.Write(err.Message);
}
finally
{
if (reader != null)
reader.Dispose();
}
但是當我試圖導入我的文件myfile.csv
,一些字符是 「uncorrectly」 編碼,如:
STATUA DELLA LIBERT�
那麼,怎樣才能編碼呢?謝謝
你是否100%確定在導入之前用記事本或記事本++打開文件顯示正確的字符而不是上面的有趣符號? – 2012-02-09 09:44:17
用記事本++打開我得到STATUA DELLA LIBERT· – markzzz 2012-02-09 09:46:01
如果字符不存在之前那麼文件有錯誤的編碼,並且不是關於CSV解析,而是關於首先獲取正確格式和編碼的文件。 – 2012-02-09 09:47:03