保存文档时 EPPlus 抛出 "The given key was not present in the dictionary."
EPPlus throwing "The given key was not present in the dictionary." when saving an document
我在 ASP.Net MVC 应用程序中使用 EPPlus 和 C# 从存储系统中读取 excel 文档。它作为字节数组 (byte[]) 返回给方法。我将字节数组转换为流,然后转换为 ExcelPackage 并修改现有工作表上的单元格。
当我将 ExcelPackage 转换回流时,将作为 FileStreamResult 提供给调用浏览器。当我执行 MemoryStream ms = new MemoryStream(excel.GetAsByteArray()); 行时我得到上面提到的异常。
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;
}
}
我花了几个小时通读 Google 和 Stack Overflow,但未能找到答案。
当我将 EPPlus 库从 4.1.0 降级到 3.1.3 时,它开始正常工作。
我在 ASP.Net MVC 应用程序中使用 EPPlus 和 C# 从存储系统中读取 excel 文档。它作为字节数组 (byte[]) 返回给方法。我将字节数组转换为流,然后转换为 ExcelPackage 并修改现有工作表上的单元格。
当我将 ExcelPackage 转换回流时,将作为 FileStreamResult 提供给调用浏览器。当我执行 MemoryStream ms = new MemoryStream(excel.GetAsByteArray()); 行时我得到上面提到的异常。
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;
}
}
我花了几个小时通读 Google 和 Stack Overflow,但未能找到答案。
当我将 EPPlus 库从 4.1.0 降级到 3.1.3 时,它开始正常工作。