CSV导入中的Unicode字符

CSV导入中的Unicode字符

本文介绍了OLE CSV导入中的Unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码段.这用于导入从全球多个位置提供给我们的CSV文件.文件格式是相同的,实际上很简单,名字,姓氏,电子邮件和一些日期以及一个或两个其他文本列.我的问题是某些非英语字符,俄语,德语,西班牙语字符未正确导入.当我查看DataTable中文件的内容时,它会生成,例如,当它应生成Андрей"时,它会生成Ðð½".我已经寻找了很长时间,似乎找不到解决方法.如果将文件保存到xls中,然后将其导入,则更改连接字符串当然可以正常工作,因此看来喷射引擎可以处理unicode字符.任何帮助,将不胜感激.如果有问题,我正在Windows 7 64位上使用VS 2010.预先感谢!

I have the following code snippet. This is used to import CSV files that are supplied to us from multiple locations around the world. The file format is the same, and actually quite simple, First Name, Last Name, Email and some dates as well as one or two other text columns. The problem I have is some non-english characters, russian, german, spanish characters are not being imported correctly. When I look at the contents of the file in the DataTable it produces, for example "Ðндрей" when it should produce "Андрей" and so on. I have looked for a very long time and cant seem to find a solutions. If I save the file into an xls and then import it, changing my connection string of course it works fine, so it seems like the jet engine could handle unicode characters. Any help would be appreciated. If it matters I am using VS 2010 on windows 7 64 bit. Thanks in advance!

  string filename = @"C:\Data\Test.csv";
  string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data;Extended Properties=""text;CharacterSet=UNICODE;HDR=Yes;FMT=Delimited"";";
  string commString = string.Format("Select * from {0}", filename);

  DataTable dt = new DataTable();
  using (OleDbConnection connection = new OleDbConnection(connString))
  {
    connection.Open();
    using (OleDbDataAdapter da = new OleDbDataAdapter(commString, connection))
    {
      da.Fill(dt);
    }
  }

推荐答案

尝试

在您用于UTF-8的连接字符串中.

within your connection string for UTF-8.

string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data;Extended Properties=""text;characterset=65001;HDR=Yes;FMT=Delimited"";";

按照链接进行操作其他代码.

Follow the link for other codes.

这篇关于OLE CSV导入中的Unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 19:24