c# - NPOI CopyTo 不起作用并显示 NPOI.XSSF.UserModel.XSSFSheet.CopySheetImages 异常
问题描述
我有一个无法使用的问题NPOI CopyTo
。
我的代码
var path = @"C:\Users\Wei\Downloads\Book2.xlsx";
var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xlsx");
File.Copy(path, tempPath);
using (var fs = new FileStream(tempPath, FileMode.OpenOrCreate, FileAccess.Read))
{
XSSFWorkbook wb = new XSSFWorkbook(fs);
ISheet ws1 = wb.GetSheetAt(0);
ws1.CopyTo(wb, "sheet2", true, true);
wb.Write(fs);
}
运行时版本:.NET Core 3.1.10
NPOI 版本:2.5.2
Book2.xlsx
错误
NullReferenceException : Object reference not set to an instance of an object.
堆栈跟踪
at NPOI.XSSF.UserModel.XSSFSheet.CopySheetImages(XSSFWorkbook destWorkbook, XSSFSheet destSheet)
at NPOI.XSSF.UserModel.XSSFSheet.CopyTo(IWorkbook dest, String name, Boolean copyStyle, Boolean keepFormulas)
at UserQuery.Main(), line 10
我检查了 var wb not null
。
解决方案
推荐阅读
- java - 如何将一张大地图分成几张小地图?
- c# - 如何根据数据库值检索或启用单选按钮?
- python - 如何在json文件中查找和替换值的一部分
- javascript - 我的编辑按钮的 ajax 不起作用
- python - 如何从机器人框架的列表中删除项目?
- java - 我需要在下拉框内滚动
- sql-server - UPDATE STATISTICS 返回错误“表不存在”。在 SQL Server 中
- asp.net - 我们可以将 asp.net 网站容器化吗?但是在 vs 2017 中没有这个选项
- java - 如何在 Spring 工具套件 (STS) 中删除 application.properties 的错误通知
- sql - 我需要使用动态 SQL 创建一个 SQL 表