asp.net mvc或者其他程序无法打开excel——解决方案,C#处理Excel文件
2024-08-25 22:31:02
问题描述:今天处理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;
}
最新文章
- Zephyr OS 简介
- Java反射机制
- 4种scope方法
- SQL Server ErrorLog
- CSS继承
- C#2.0 to 4.0
- mfc中Button、Edit Control和MFC EditBrowse Control的用法
- (转)github设置添加SSH
- php100 的下拉分页效果
- == 和equals比较
- cocos2dx shader实现灰度图android后台切换回来导致图像偏移的问题
- Android大图片导致内存问题小结
- Oracle 中的Top写法
- linux-touch
- 【转】Visual Studio Code 使用Git进行版本控制
- 双目深度估计传统算法流程及OpenCV的编译注意事项
- Java线程池不错的总结博客
- 最大熵与最大似然,以及KL距离。
- 每天学点SpringCloud(一):使用SpringBoot2.0.3整合SpringCloud
- SCU 4438 Censor(Hash)题解
热门文章
- 我为什么要谈KeepAlive(文末增加nginx 负载tcp长连接保持 demo)
- ubuntu使用遇到的问题
- 6.04-news_xpath3
- 利用ENVI FX从RGB提取建筑物轮廓
- Qt编译错误GL/gl.h: No such file or directory
- UVA11093-Just Finish it up(思维)
- spring mybatis整合
- element not interactable,这种提示表示元素当前在页面上不可见
- 洛谷 P1706 全排列问题
- python中join()函数的使用方法