[英]EPPlus throwing “The given key was not present in the dictionary.” when saving an document
I am using EPPlus and C# in an ASP.Net MVC application to read an excel document out of a storage system. 我在ASP.Net MVC应用程序中使用EPPlus和C#从存储系统中读取Excel文档。 It is returned as a byte array (byte[]) to the method. 它以字节数组(byte [])的形式返回给该方法。 I convert the byte array to a stream and then to an ExcelPackage and modify the cells on the existing worksheets. 我将字节数组转换为流,然后转换为ExcelPackage并修改现有工作表上的单元格。
When I convert the ExcelPackage back to a stream, to be served to the calling browser as a FileStreamResult. 当我将ExcelPackage转换回流时,将作为FileStreamResult提供给调用浏览器。 When I execute the line MemoryStream ms = new MemoryStream(excel.GetAsByteArray()); 当我执行行MemoryStream ms = new MemoryStream(excel.GetAsByteArray()); I get the above referenced exception. 我得到上面引用的异常。
public ActionResult Export(string id)
{
// Get the Excel document from storage
MemoryStream ohDoc = new MemoryStream();
ohDoc.Write(doc.data, 0, doc.data.Length);
ohDoc.Position = 0;
ExcelPackage excel = new ExcelPackage(ohDoc);
var workBook = excel.Workbook;
var bidInfo = excel.Workbook.Worksheets["BID INFO"];
var recap = excel.Workbook.Worksheets["RECAP"];
// Modify the worksheets ...
MemoryStream ms = new MemoryStream(excel.GetAsByteArray());
ms.Position = 0;
FileStreamResult fileStreamResult = new FileStreamResult(ms, doc.MIMEType);
fileStreamResult.FileDownloadName = doc.FileName;
return fileStreamResult;
}
}
I have spent hours reading through Google and Stack Overflow and have not been able to find an answer. 我已经花了几个小时阅读Google和Stack Overflow,却找不到答案。
当我将EPPlus库从4.1.0降级到3.1.3时,它开始正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.