----------------------------------------------------------
- .net NPOI C#处理Excel的类库使用
https://www.nuget.org/packages/NPOI/
VS->工具->程序包管理器控制台 运行 PM> Install-Package NPOI -Version 2.3.0
相关DLL引用自动添加到项目中,命名空间中添加如下声明:
using NPOI.XSSF.UserModel;
using NPOI.SS.UserModel;

-------------------------------------------------------
- 用nuget下载旧版本的软件包
SharpZipLib 必须用0.86版本的,否则NPOI打开EXCEL时会出错。
如果更新了SharpZipLib到1.0.0版本,必须roll back到0.86.0版,或者卸载重新安装NPOI。

在Visual Studio中打开包管理器控制台 – 它在工具/ NuGet包管理器/包管理器控制台中。然后运行Install-Package命令:
Install-Package ICSharpCode.SharpZipLib -Version 0.86.0.518 或者0.86.0

编辑:
为了列出包的版本,您可以使用带有远程参数和过滤器的Get-Package命令:

Get-Package -ListAvailable -Filter Common.Logging -AllVersions
通过在Install-Package命令中的版本选项后按Tab键,可以获得最新可用版本的列表。

I also met this problem with VS2017, NPOI 2.3.0 and SharpZipLib 1.0.0.
I didn't solve the problem changing the verison of the SharpZipLib to 0.86 in NuGet. After test, I found that it should also delete the below content in the App.config if it has that:

<assemblyIdentity name="ICSharpCode.SharpZipLib" publicKeyToken="1b03e6acf1164f73" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.0.0.999" newVersion="1.0.0.999"/>
So that, not only roll back the verison of the SharpZipLib to 0.86, but also modify the App.config.

------------------------------------------------------------
Excel 用NPOI编辑写入后打不开,尝试以下解决:
FileMode.Open is working with .xls files but not .xlsx files.
using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
workbook.Write(file);
}

I think the problem is that you are reading from, and writing to, the same FileStream. You should be doing the read and write using separate streams. Try it like this:

string newPath = @"C:\MyPath\test.xlsx";

// read the workbook
IWorkbook wb;
using (FileStream fs = new FileStream(newPath, FileMode.Open, FileAccess.Read))
{
wb = new XSSFWorkbook(fs);
}

// make changes
ISheet s = wb.GetSheetAt(0);
IRow r = s.GetRow(0) ?? s.CreateRow(0);
ICell c = r.GetCell(1) ?? r.CreateCell(1);
c.SetCellValue("test2");

// overwrite the workbook using a new stream
using (FileStream fs = new FileStream(newPath, FileMode.Create, FileAccess.Write))
{
wb.Write(fs);
}

.net NPOI C#处理Excel的类库使用的更多相关文章

  1. Npoi导入导出Excel操作

    之前公司的一个物流商系统需要实现对订单的批量导入和导出,翻阅了一些资料,最后考虑使用NPOI实现这个需求. 在winform上面实现excel操作:http://www.cnblogs.com/Cal ...

  2. C# 使用 NPOI 库读写 Excel 文件

    NPOI 是开源的 POI 项目的.NET版,可以用来读写Excel,Word,PPT文件.在处理Excel文件上,NPOI 可以同时兼容 xls 和 xlsx.官网提供了一份 Examples,给出 ...

  3. 一个方便且通用的导出数据到 Excel 的类库

    一个方便且通用的导出数据到 Excel 的类库 起源: 之前在做一个项目时,客户提出了许多的导出数据的需求: 导出用户信息 导出业务实体信息 各种查询都要能导出 导出的数据要和界面上看到的一致 可以分 ...

  4. Excel操作类库最常用到的4种开源项目与MS Excel类库写操作对比分析性能

    4种开源Excel读写类库与MS Excel类库写操作对比 软件开发过程中,经常需要将数据保存为.xls或.xlsx文件.之前发现微软提供的Microsoft.Office.Interop.Excel ...

  5. NPOI导入导出EXCEL通用类,供参考,可直接使用在WinForm项目中

    以下是NPOI导入导出EXCEL通用类,是在别人的代码上进行优化的,兼容xls与xlsx文件格式,供参考,可直接使用在WinForm项目中,由于XSSFWorkbook类型的Write方法限制,Wri ...

  6. .net利用NPOI导入导出Excel

    NPOI在.net中的操作Excel 1.读取 using (FileStream stream = new FileStream(@"c:\客户资料.xls", FileMode ...

  7. NPOI导入导出Excel

    .net mvc利用NPOI导入导出excel 注意:如何导出的提交方式ajax导出是失效的! 解决方案是:js处理l两个表单的提交  代码:  第一步. 在页面里面加入2个隐藏的iframe, 如下 ...

  8. NPOI 2.0 Excel读取显示

    NPOI 2.0 Excel读取显示   最近接到需求,需要把excel表格里的数据原样展示到web页面,主要是满足随意跨行跨列. 之前用过一点NPOI,不过接触的不太多,趁这次机会再熟悉一下.由于操 ...

  9. ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案 try.dot.net 的正确使用姿势 .Net NPOI 根据excel模板导出excel、直接生成excel .Net NPOI 上传excel文件、提交后台获取excel里的数据

    ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案   ASP.NET Core 从2.2版本开始,采用了一个新的名为Endpoint的路由方案,与原来的方案在使用上差别不 ...

随机推荐

  1. 外引js — 先引入cdn,cdn失效时引入本地js

    参考:http://www.tianshan277.com/563.html 效果: html: <!DOCTYPE html> <html lang="en"& ...

  2. MFC注册热键

    注册热键. 当用户点击注册的快捷键时,做出相应的响应. 定义 ALT+M键为测量按钮响应函数: 头文件中定义: #define ID_HOTKEY1 10001 在初始化函数中加入注册热键函数: if ...

  3. webservice、httpClient、dubbo的区别

    在开发中,对于同一个war包中的对象方法我们可以直接调用,但是很多情况下需要在不同项目或者不同服务器进行相互调用 webservice webservice技术可以实现不同服务器项目直接的调用和交换数 ...

  4. Luogu P1131 [ZJOI2007]时态同步(dfs)

    P1131 [ZJOI2007]时态同步 题意 题目描述 小\(Q\)在电子工艺实习课上学习焊接电路板.一块电路板由若干个元件组成,我们不妨称之为节点,并将其用数字\(1,2,3,\dots\).进行 ...

  5. python所有的标准异常类

    异常名称 描述 BaseException 所有异常的基类 SystemExit 解释器请求退出 KeyboardInterrupt 用户中断执行(通常是输入^C) Exception 常规错误的基类 ...

  6. 扩展kmp板子

    using namespace std; #include <cstdio> #include <cstring> #include <algorithm> #de ...

  7. RabbitMQ代码操作之发消息和序列化机制

    几个自动配置类: 1.RabbitAutoConfiguration2.有自动配置了连接工厂 ConnectionFactory3.RabbitProperties 封装了RabbitMQ的配置4.R ...

  8. spark Infinate 的处理

    去掉infinity数据的方法: absperrordf_rdd = absperrordf.rdd.filter(lambda x: (np.isinf(float(x.avgperror)) == ...

  9. nc 文件的nan识别

    表现形式:print()结果为 --      打印type为numpy.ma.core.MaskedConstant 使用 if type(x) == np.ma.core.MaskedConsta ...

  10. 国内有哪些质量高的JAVA社区?

    国内有哪些质量高的JAVA社区? 转自:http://www.zhihu.com/question/29836842#answer-13737722 并发编程网 - ifeve.com 强烈推荐 Im ...