2

我正在使用 asp.net 4.5 框架。我刚刚使用 NUget Package 下载了 EPPLus。然后我使用了以下链接中给出的代码。

http://epplus.codeplex.com/wikipage?title=WebapplicationExample

并在按钮的单击事件上添加以下代码。单击按钮后,我收到以下错误。

无法加载文件或程序集“EPPlus,Version=3.1.3.0,Culture=neutral,PublicKeyToken=ea159fdaa78159a1”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)

如果我犯了任何愚蠢的错误,请提出建议。

在此处输入图像描述

DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));

table.Rows.Add(25, "Indocin", "David", DateTime.Now);
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);

using (ExcelPackage pck = new ExcelPackage())
{
    //Create the worksheet
    ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");

    //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
    ws.Cells["A1"].LoadFromDataTable(table, true);

    //Format the header for column 1-3
    using (ExcelRange rng = ws.Cells["A1:C1"])
    {
        rng.Style.Font.Bold = true;
        rng.Style.Fill.PatternType = ExcelFillStyle.Solid;                      //Set Pattern for the background to Solid
        rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189));  //Set color to dark blue
        rng.Style.Font.Color.SetColor(Color.White);
    }


    //Write it back to the client
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.AddHeader("content-disposition", "attachment;  filename=ExcelDemo.xlsx");
    Response.BinaryWrite(pck.GetAsByteArray());
}
4

2 回答 2

5

我遇到了一个案例,我的解决方案是为测试目的而准备的,并且由几个参考 EPPlus 的项目组成。问题是我仅将版本 4 引用到一个项目,而我将其他项目留给了旧版本的 EPPlus(尤其是可执行文件的版本较旧)。结果是,在构建过程之后,该文件夹包含较旧的 EPPlus,并且在运行时我使用了带有较新 EPPlus 的链接项目(因此该项目无法找到正确版本的 EPPlus)。在我为所有项目引用相同版本的 EPPlus 后,不再抛出异常。

于 2014-12-06T16:08:09.787 回答
0

这部分

找到的程序集的清单定义与程序集引用不匹配。

建议程序集的版本号与您的配置文件中的版本号不匹配。看到这个问题:定位程序集的清单定义与程序集引用不匹配

于 2013-08-15T17:37:26.530 回答