<i id='eCN1x'><tr id='eCN1x'><dt id='eCN1x'><q id='eCN1x'><span id='eCN1x'><b id='eCN1x'><form id='eCN1x'><ins id='eCN1x'></ins><ul id='eCN1x'></ul><sub id='eCN1x'></sub></form><legend id='eCN1x'></legend><bdo id='eCN1x'><pre id='eCN1x'><center id='eCN1x'></center></pre></bdo></b><th id='eCN1x'></th></span></q></dt></tr></i><div id='eCN1x'><tfoot id='eCN1x'></tfoot><dl id='eCN1x'><fieldset id='eCN1x'></fieldset></dl></div>

      1. <tfoot id='eCN1x'></tfoot>
          <bdo id='eCN1x'></bdo><ul id='eCN1x'></ul>
        <legend id='eCN1x'><style id='eCN1x'><dir id='eCN1x'><q id='eCN1x'></q></dir></style></legend>
      2. <small id='eCN1x'></small><noframes id='eCN1x'>

        Shaman.EPPlus + ASP.NET Core MVC - 部分已经存在异常

        Shaman.EPPlus + ASP.NET Core MVC - Part already exist exception(Shaman.EPPlus + ASP.NET Core MVC - 部分已经存在异常)

            <tfoot id='pPron'></tfoot>

              <i id='pPron'><tr id='pPron'><dt id='pPron'><q id='pPron'><span id='pPron'><b id='pPron'><form id='pPron'><ins id='pPron'></ins><ul id='pPron'></ul><sub id='pPron'></sub></form><legend id='pPron'></legend><bdo id='pPron'><pre id='pPron'><center id='pPron'></center></pre></bdo></b><th id='pPron'></th></span></q></dt></tr></i><div id='pPron'><tfoot id='pPron'></tfoot><dl id='pPron'><fieldset id='pPron'></fieldset></dl></div>
            1. <legend id='pPron'><style id='pPron'><dir id='pPron'><q id='pPron'></q></dir></style></legend>
                • <bdo id='pPron'></bdo><ul id='pPron'></ul>

                  <small id='pPron'></small><noframes id='pPron'>

                    <tbody id='pPron'></tbody>
                  本文介绍了Shaman.EPPlus + ASP.NET Core MVC - 部分已经存在异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Shaman.EPPlus,应该兼容的 EPPlus 版本使用 ASP.NET Core MVC.我正在尝试将对象集合导出为 xlxs 文件.代码如下所示:

                  I am using Shaman.EPPlus, a version of EPPlus that should be compatible with ASP.NET Core MVC. I am trying to export a collection of object as xlxs file. The code looks like this:

                  foreach(var client in clientsToExport)
                  {
                      clientList.Add(new object[] { "FirstName", client.FirstName });
                  }
                  
                  MemoryStream stream = new MemoryStream();         
                  using (ExcelPackage pck = new ExcelPackage(stream))
                  {
                      ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Clients");
                      ws.Cells["A1"].LoadFromArrays(clientList);
                      pck.Save();
                  
                      Response.Clear();
                      Response.Headers.Add("content-disposition", "attachment;  filename=Clients.xlsx");
                      Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                      var bytes = pck.GetAsByteArray();
                      Response.Body.WriteAsync(bytes, 0, bytes.Length);
                  }
                  

                  调用GetAsByteArray方法时似乎抛出了包含Par已经存在"消息的异常.

                  It seems that an exception containing the message "Par already exist" is thrown when GetAsByteArray method is called.

                  在 OfficeOpenXml.Packaging.ZipPackage.CreatePart(Uri partUri, String contentType, CompressionLevel compressionLevel)
                  在 OfficeOpenXml.ExcelWorkbook.Save()
                  在 OfficeOpenXml.ExcelPackage.GetAsByteArray(布尔保存)

                  at OfficeOpenXml.Packaging.ZipPackage.CreatePart(Uri partUri, String contentType, CompressionLevel compressionLevel)
                  at OfficeOpenXml.ExcelWorkbook.Save()
                  at OfficeOpenXml.ExcelPackage.GetAsByteArray(Boolean save)

                  你知道我可以检查什么吗?

                  Do you know what could I check?

                  推荐答案

                  问题出在这几行:

                  pck.Save();
                  ....
                  var bytes = pck.GetAsByteArray();
                  

                  这两个调用都会导致包被 Epplus 关闭.您不需要 .Save 调用,因为无论如何 .GetAsByteArray 都会自动调用它,因此只需删除第一行即可.

                  Both calls will cause the package to be closed by Epplus. You do not need the .Save call since that will automatically be called by .GetAsByteArray anyway so simply remove the first line.

                  这篇关于Shaman.EPPlus + ASP.NET Core MVC - 部分已经存在异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding DbContextOptions in Startup.cs not registering data store(在 Startup.cs 中添加 DbContextOptions 未注册数据存储)
                  Migrate html helpers to ASP.NET Core(将 html 帮助程序迁移到 ASP.NET Core)
                  Conditional validation in MVC.NET Core (RequiredIf)(MVC.NET Core 中的条件验证(RequiredIf))
                  Is it possible to serve static files from outside the wwwroot folder?(是否可以从 wwwroot 文件夹外部提供静态文件?)
                  Working with multiple resultset in .net core(在 .net 核心中使用多个结果集)
                  Where all types for http headers gone in ASP.NET 5?(ASP.NET 5 中所有类型的 http 标头都去了哪里?)

                      <legend id='a4Dwi'><style id='a4Dwi'><dir id='a4Dwi'><q id='a4Dwi'></q></dir></style></legend>

                        <small id='a4Dwi'></small><noframes id='a4Dwi'>

                          <tbody id='a4Dwi'></tbody>

                        • <i id='a4Dwi'><tr id='a4Dwi'><dt id='a4Dwi'><q id='a4Dwi'><span id='a4Dwi'><b id='a4Dwi'><form id='a4Dwi'><ins id='a4Dwi'></ins><ul id='a4Dwi'></ul><sub id='a4Dwi'></sub></form><legend id='a4Dwi'></legend><bdo id='a4Dwi'><pre id='a4Dwi'><center id='a4Dwi'></center></pre></bdo></b><th id='a4Dwi'></th></span></q></dt></tr></i><div id='a4Dwi'><tfoot id='a4Dwi'></tfoot><dl id='a4Dwi'><fieldset id='a4Dwi'></fieldset></dl></div>
                          <tfoot id='a4Dwi'></tfoot>
                          • <bdo id='a4Dwi'></bdo><ul id='a4Dwi'></ul>