简体   繁体   English

在C#中读取带有特殊字符的Excel工作表时出现问题

[英]Problem in reading Excel Sheet with Special Character in C#

I am Using OLEDB to read Excel Sheet with C#. 我正在使用OLEDB使用C#读取Excel工作表。 In that Column header Name is "Sr.No." 在该列标题中,名称为“ Sr.No.”。 in my "Sheet1". 在我的“ Sheet1”中。 When i fetch Excel Sheet Data into my Datatable , i am getting "Sr#No#" as a column header name instead of original one. 当我将Excel Sheet Data提取到Datatable中时,我将“ Sr#No#”作为列标题名称而不是原始名称。 Can you please tell me why it's happening so? 你能告诉我为什么会这样吗? And what is the solution for the same. 相同的解决方案是什么。

Thanks. 谢谢。

After some testing I've found out that OleDB converts the following characters: 经过一些测试,我发现OleDB可以转换以下字符:

. becomes # 变成#

! becomes _ 成为_

` becomes _ `变成_

[ becomes ( [变成(

] becomes ) ]变成)

All the other characters are read correctly. 其他所有字符均正确读取。 Hope this helps someone. 希望这对某人有帮助。

Best Regards. 最好的祝福。

Googling around suggests that this is an inherent feature of OLEDB, rather than being anything to do with Excel - it seems to simply not like periods (.) in column names. 谷歌搜索表明这是OLEDB的固有功能,而不是与Excel无关-它似乎根本不喜欢列名中的句点(。)。

My suggestions would be either to cope with it - it seems to be a deterministic replacement of .s with #s - or if possible use an alternative means of reading Excel data from C# (search this site for alternatives). 我的建议是应付它-似乎是用#s替换.s的确定性-或如果可能的话,使用从C#读取Excel数据的替代方法(在本网站中搜索替代方法)。

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

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