问题描述:今天处理Excel时遇到一个问题,本地使用Microsoft.Jet.OLEDB.4.0处理,正常完成了需求,

上传到服务器后发生了异常,通过排查发现问题出现在对Excel文件的读取上,然后推测是因为

没有安装对应的驱动,然后在微软官网查到了Microsoft.ACE.OLEDB.12.0;这个驱动,

服务器上安装后变成功解决了此问题,同时需要注意,连接字符串需要改成Microsoft.ACE.OLEDB.12.0;

示例

public static DataSet ExcelToDS(string Path)
{
//string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
//发布后开启此注释
string strConn = "Provider=Microsoft.ACE.OLEDB.12.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;
}

最新文章

  1. Zephyr OS 简介
  2. Java反射机制
  3. 4种scope方法
  4. SQL Server ErrorLog
  5. CSS继承
  6. C#2.0 to 4.0
  7. mfc中Button、Edit Control和MFC EditBrowse Control的用法
  8. (转)github设置添加SSH
  9. php100 的下拉分页效果
  10. == 和equals比较
  11. cocos2dx shader实现灰度图android后台切换回来导致图像偏移的问题
  12. Android大图片导致内存问题小结
  13. Oracle 中的Top写法
  14. linux-touch
  15. 【转】Visual Studio Code 使用Git进行版本控制
  16. 双目深度估计传统算法流程及OpenCV的编译注意事项
  17. Java线程池不错的总结博客
  18. 最大熵与最大似然,以及KL距离。
  19. 每天学点SpringCloud(一):使用SpringBoot2.0.3整合SpringCloud
  20. SCU 4438 Censor(Hash)题解

热门文章

  1. 我为什么要谈KeepAlive(文末增加nginx 负载tcp长连接保持 demo)
  2. ubuntu使用遇到的问题
  3. 6.04-news_xpath3
  4. 利用ENVI FX从RGB提取建筑物轮廓
  5. Qt编译错误GL/gl.h: No such file or directory
  6. UVA11093-Just Finish it up(思维)
  7. spring mybatis整合
  8. element not interactable,这种提示表示元素当前在页面上不可见
  9. 洛谷 P1706 全排列问题
  10. python中join()函数的使用方法