错误提示:
“System.IO.FileLoadException”类型的异常在 Utility.dll 中发生,但未在用户代码中进行处理
其他信息: 未能加载文件或程序集“NPOI, Version=2.4.0.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)
我的代码如下:
FileInfo fi = new FileInfo(file.FileName);
string houzui = fi.Extension; //文件扩展名
string dir = DateTime.Now.ToString("yyyyMMdd");
string abpath = Server.MapPath($"/upload/{dir}/");
if (!Directory.Exists(abpath))
{
Directory.CreateDirectory(abpath);
}
string slt = Server.MapPath($"/upload/{dir}/slt/");
if (!Directory.Exists(slt))
{
Directory.CreateDirectory(slt);
}
string newname = Guid.NewGuid().ToString().Substring(0, 6) + houzui;
file.SaveAs(abpath + newname);
string physicalPath = abpath + newname;
DataTable dt = Tool.RenderDataTableFromExcel(physicalPath);
public static DataTable RenderDataTableFromExcel(string path)
{
DataTable dt = new DataTable();
HSSFWorkbook hssfworkbook;
using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
{
hssfworkbook = new HSSFWorkbook(file);
}
HSSFSheet sheet = (HSSFSheet)hssfworkbook.GetSheetAt(0);
System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
HSSFRow headerRow = (HSSFRow)sheet.GetRow(0);
int cellCount = headerRow.LastCellNum;
for (int j = 0; j < cellCount; j++)
{
HSSFCell cell = (HSSFCell)headerRow.GetCell(j);
if (cell == null)
{
dt.Columns.Add("");
}
else
{
dt.Columns.Add(cell.ToString());
}
}
for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++)
{
HSSFRow row = (HSSFRow)sheet.GetRow(i);
if (row == null)
{
continue;
}
DataRow dataRow = dt.NewRow();
for (int j = row.FirstCellNum; j < cellCount; j++)
{
if (row.GetCell(j) != null)
dataRow[j] = row.GetCell(j).ToString();
}
dt.Rows.Add(dataRow);
}
return dt;
}
检查下实际调用的dll版本和项目引用的dll版本是否一致
谢谢,可以了