简体   繁体   English

保存文档时,EPPlus抛出“词典中不存在给定的键”。

[英]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.

相关问题 字典中不存在给定的键。 哪个键? - The given key was not present in the dictionary. Which key? 给定的键在词典中不存在。 C# - The given key was not present in the dictionary. c# 字典中不存在给定的键。 用 mysql - The given key was not present in the dictionary. with mysql 给定的键在词典中不存在。 使用解析对象 - The given key was not present in the dictionary. Using Parse Object CRM - 工作流活动 - 错误:字典中不存在给定的密钥。 - CRM - Workflow Activity - Error: The given key was not present in the dictionary. 字典中不存在给定的键。 mysql 数据库 C# 中的错误 - The given key was not present in the dictionary. error in mysql database c# 出现错误错误:字典中不存在给定的键。 在生产中 - Getting error Error: The given key was not present in the dictionary. in production 无法读取 EWS 中的 contact.addresses。 所有联系人读取显示“字典中不存在给定的键。” - Trouble reading contact.addresses in EWS. All contacts read display "The given key was not present in the dictionary." System.Collections.Generic.KeyNotFoundException: '字典中不存在给定的键。' C# 窗口应用程序 - System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary.' C# windows application 给定的密​​钥不在字典中 - given key was not present in the dictionary
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM