询问者
请问vs2017为什么读取excel 文件报错?

问题
-
发生了 System.Data.OleDb.OleDbException
HResult=0x80004005
Message=外部数据库驱动程序 (1) 中的意外错误。
Source=Microsoft JET Database Engine
StackTrace:
在 Business.getExcelTable(String ExcelFile) 在 d:\develop\business2014\App_Code\Business.cs 中: 第 432 行
在 telecomm_bill_basic_data_input.ButtonBatchInput_Click(Object sender, EventArgs e) 在 d:\develop\business2014\dev\dev_prepare_single.aspx.cs 中: 第 1289 行读取代码是通用的
public DataSet ExcelToDS(string Path) { 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; DataSet ds = null; strExcel="select * from [sheet1$]"; myCommand = new OleDbDataAdapter(strExcel, strConn); ds = new DataSet(); myCommand.Fill(ds,"table1"); return ds; }
- 已编辑 尺蠖 2017年10月20日 8:29
全部回复
-
现在是只能用Microsoft Access Database Engine 2010 Redistributable方式读取xlsm格式excel了
public static DataTable getExcelTable(string ExcelFile) { DataSet ds = new DataSet(); string strConn = "Provider=Microsoft.Ace.OleDb.12.0;Data Source= " + ExcelFile + "; Extended Properties='Excel 12.0;HDR=No'"; //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + ExcelFile + "; Extended Properties='Excel 8.0;HDR=No'"; OleDbDataAdapter oada = new OleDbDataAdapter("select * from [Sheet1$]", strConn); oada.Fill(ds); return ds.Tables[0]; }
-
非常感谢,今天才发现closexml插件不能打开.xls文件,换用了NPOI,挺好用的