我正在使用 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)
如果我犯了任何愚蠢的错误,请提出建议。
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/