简体   繁体   English

使用OleDb或ExcelDataReader读取Excel文件将返回wronlgy编码的特殊字符

[英]Reading Excel files with OleDb or ExcelDataReader return special characters encoded wronlgy

I need to read an EXCEL binary file (xls) in C#. 我需要在C#中读取EXCEL二进制文件(xls)。

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? Excel文件是否完全像编码一样?

The string in the Excel File is Excel文件中的字符串是

Lydia Hömmerl 莉迪亚·霍默(LydiaHömmerl)

When reading with Jet or EDR i get: 使用Jet或EDR读取时,我得到:

Lydia HŠmmerl 莉迪亚·希尔默(LydiaHŠmmerl)

I have tried OleDb and the Excel Data Reader project. 我已经尝试过OleDb和Excel Data Reader项目。

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]);

Unicode with C# Unicode与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. 它提到了一些高级主题,但是仅是为了使读者意识到它们的存在,而没有就该主题提供太多指导。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM