C# 採用OLDB方式連線EXCEL

weixin_34119545發表於2012-05-16

當Office 2007來的時候,C#連線EXCEL,連線引擎發生了變化,對於2007和2010來說,連線引擎是Microsoft.ACE.OLEDB.12.0,所以在這兩個下的練級字串為:

 OleDbConnection con = new OleDbConnection();
            con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + fileName + ";" + "Extended ProPerties= \"Excel 12.0;HDR=Yes;\"";

 

在office 2003中連線字串為
 OleDbConnection con = new OleDbConnection();
            con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=Excel 8.0;";  

 

更多資訊請見:http://msdn.microsoft.com/zh-cn/library/ff965871.aspx

相關文章