asp.net - EPplus 装配错误

标签 asp.net .net epplus

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

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

然后在按钮的点击事件上添加以下代码。单击按钮后,出现以下错误。

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

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

enter image description here

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());
}

最佳答案

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

关于asp.net - EPplus 装配错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18258319/

相关文章:

javascript - Web API MVC 从 ng-table 获取查询参数?

c# - 使用 C# .net 从 byte[] 获取位图句柄 (IntPtr)

c# - EPPlus:创建排序列

C#:EPPLUS:LoadFromCollection

c# - 如何在Web应用程序而不是C#中的Windows应用程序中创建sqlite文件

c# - 相当于 FromQuery 属性的 Razor

asp.net - 即使在完成所有可能的设置后,使用 IIS 7 的 asp.net 2.0 中的超时和自动注销

c# - 对 Key 和 IV 使用相同值的缺点?

c# - Word VSTO - 向 Word 文件添加标签

C# EPPLUS 无法获取单元格值