C# .NET OLEDB 访问Excel文件

连接串范例

Provider=Microsoft.Jet.OLEDB.4.0;Data Source="D:\My Works\AN45S01283.xls";Persist Security Info=False;Extended Properties="Excel 8.0;HDR=YES;IMEX=1"

excel 2000 ~ 2003的 OleDb 连接串的格式如下:
Provider=Microsoft.Jet.OleDb.4.0;Data Source='excel文件路径';Extended Properties='Excel 8.0;HDR=YES'

excel 2007 的 OleDb 的连接串的格式如下:

Provider=Microsoft.Ace.OleDb.12.0;Data Source='excel文件路径';Extended Properties='Excel 12.0;HDR=YES'

Excel2000-2003:

OleDbConnection ExcelConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + FilePath + "; Extended Properties='Excel 12.0;HDR=YES;IMEX=1'");

Excel2007:
OleDbConnection ExcelConn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + FilePath + "; Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1'");

posted @ 2010-12-24 01:33  抱影无眠  阅读(1108)  评论(0编辑  收藏  举报