使用oledb代表阅读 [英] excel reading using oledb rep

查看:102
本文介绍了使用oledb代表阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有一个问题,我正在使用oledb读取Excel文件并将其转换为DataTable,所以每当我从Excel中获取数据时,用Ó替换某些特殊字符会替换为'? '但是我希望角色保持原样



我的Excel文件读取数据代码



Hello
I Have A problem that im reading an Excel file using oledb and Convert that into DataTable so whenever i fetch data from Excel that replace Some Special characters with like 'Ó' replaces with '?' But i want that characters remains as it is

my Code for Reading Data from Excel file

private DataSet getData(string Path)
        {
            string fileName = Path;
            string connectionString = @"Provider=Microsoft.ACE.OLEDB.14.0;Data Source="+fileName+";ExtendedProperties="+"Excel 12.0;HDR=YES;";
            OleDbConnection con = new System.Data.OleDb.OleDbConnection(connectionString);
            con.Open();
            OleDbDataAdapter cmd = new System.Data.OleDb.OleDbDataAdapter("select * from [SHEET1$]", con);
            DataSet excelDataSet = new DataSet();
            cmd.Fill(excelDataSet);
            
            con.Close();
            return  excelDataSet;
        }





---------------------- --------

*输入 - > RamÓnyCajal,


*实际产出 - > Ram?n y Cajal,


*预期产出 - > RamÓnyCajal,






我认为这是因为字符编码格式。

请帮忙我



------------------------------
*Input -> RamÓn y Cajal,

*Actual Output -> Ram?n y Cajal,

*Expected Output -> RamÓn y Cajal,



I think its because of Character encoding Format .
Please help me


推荐答案

,con);
DataSet excelDataSet = new DataSet();
cmd.Fill(excelDataSet);

con.Close();
return excelDataSet;
}
", con); DataSet excelDataSet = new DataSet(); cmd.Fill(excelDataSet); con.Close(); return excelDataSet; }





---- --------------------------

*输入 - >RamÓnykajal,


*实际产量 - > Ram?ny Cajal,


*预期产量 - >RamÓnyCajal,






我认为这是因为字符编码格式。

请帮助我



------------------------------
*Input -> RamÓn y Cajal,

*Actual Output -> Ram?n y Cajal,

*Expected Output -> RamÓn y Cajal,



I think its because of Character encoding Format .
Please help me



plz尝试此连接字符串

plz try this connection string
strExcelCon = @"Provider=Microsoft.ACE.OLEDB.14.0;Data Source=" + sExcelPath + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";


这篇关于使用oledb代表阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆