使用 OleDb 或 ExcelDataReader 读取 Excel 文件会返回编码错误的特殊字符
我需要用 C# 读取 EXCEL 二进制文件 (xls)。
基本上它可以工作,但是我遇到了错误编码的字符(例如德语元音变音)的问题。
有什么方法可以指定编码吗? Excel 文件是否有类似编码之类的东西?
Excel 文件中的字符串是
莉迪亚·霍默尔
当使用 Jet 或 EDR 阅读时,我得到:
莉迪亚·赫默尔
我尝试过 OleDb 和 Excel Data Reader 项目。
这是我用来打开和读取文件的代码:
var connectionString =
string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0};
Extended Properties=\"Excel 8.0;HDR=no\";", filePath);
var adapter = new OleDbDataAdapter(
"SELECT * FROM [Webshop orders$]", connectionString);
var ds = new DataSet();
adapter.Fill(ds, "Orders");
var data = ds.Tables["Orders"].AsEnumerable();
foreach (var row in data)
{
var str = Convert.ToString(row[0]);
I need to read an EXCEL binary file (xls) in C#.
Basically its working, but i have problems with wrongly encoded characters (german umlauts for example).
Is there some way to specify an encoding? Does Excel files have something like an encoding at all?
The string in the Excel File is
Lydia Hömmerl
When reading with Jet or EDR i get:
Lydia HŠmmerl
I have tried OleDb and the Excel Data Reader project.
Here is the code i use to open and read the file:
var connectionString =
string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0};
Extended Properties=\"Excel 8.0;HDR=no\";", filePath);
var adapter = new OleDbDataAdapter(
"SELECT * FROM [Webshop orders$]", connectionString);
var ds = new DataSet();
adapter.Fill(ds, "Orders");
var data = ds.Tables["Orders"].AsEnumerable();
foreach (var row in data)
{
var str = Convert.ToString(row[0]);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Unicode with C#
还是有很多人不明白二进制和文本的区别,或者知道什么是字符编码等等。这个页面就是为这些人编写的。它提到了一些高级主题,但只是为了让读者意识到它们的存在,而不是对该主题提供太多指导。
Unicode with C#
There are still many people who don't understand the difference between binary and text, or know what a character encoding is, etc. It is for these people that this page has been written. It mentions a few advanced topics, but only to make the reader aware of their existence, rather than to give much guidance on the topic.