- string strConn = string.Empty ;
- //判断xls 的版本2003--2007
- if(System.IO.Path.GetExtension(excelFileName).Equals(".xls"))
- {
- strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelFileName + ";Extended Properties='Excel 8.0;HDR=YES'";
- }
- else if(System.IO.Path.GetExtension(excelFileName).Equals(".xlsx"))
- {
- strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFileName + ";Extended Properties='Excel 12.0;HDR=YES'";
- }
1 。ConnString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" + filepath + "; Extended Properties=‘Excel 8.0; HDR=No; IMEX=1’ ";
折腾了半天 原来是字符串弄错了。少了分号
2。。 还是要注意版本问题 2003 与 2007 连接打开字符串的区别