c# 导入Excel07时,“引发System.InvalidOperationException”
导入Excel时,在conn.Open()时,出现“con.ServerVersion引发System.InvalidOperationException”异常,从而Open()失败,报错的意思是说版本不对,求指点!导入代码如下:string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
if (tablename2.Length > 0 && !tablename2.Equals(string.Empty))
TableName = tablename2;
strExcel = "select * from [" + TableName + "$]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
DataTable dt = new DataTable();
myCommand.Fill(dt);
conn.Close();
return dt; --------------------编程问答-------------------- 貌似Excel2007,必须用Microsoft.ACE.OLEDB.12.0,而不是Jet4.0 --------------------编程问答-------------------- 在本机运行的时候,4.0是可以的,发布到到服务器之后,就出现版本不对的情况,求指点! --------------------编程问答-------------------- http://blog.csdn.net/shulin85/article/details/7231560 --------------------编程问答-------------------- Excel2007,2010的连接方法
http://connectionstrings.com/excel-2007
补充:.NET技术 , C#