导入

public ActionResult daoru(HttpPostedFileBase ExcFile)
{
HttpPostedFileBase file = Request.Files["ExcFile"];
Stream stre = file.InputStream;

HSSFWorkbook book = new HSSFWorkbook(stre);
ISheet sheet = book.GetSheetAt(0);
DataTable dt = new DataTable();
IRow row = sheet.GetRow(0);

int cellcount = row.LastCellNum;
int rowcount = sheet.LastRowNum;

for (int i = 0; i < cellcount; i++)
{
DataColumn column = new DataColumn(row.GetCell(i).StringCellValue);
dt.Columns.Add(column);
}
for (int i = 1; i < rowcount; i++)
{
IRow rows = sheet.GetRow(i);
DataRow datarow = dt.NewRow();

for (int j = 0; j < cellcount; j++)
{
datarow[j] = rows.GetCell(j);
}
dt.Rows.Add(datarow);
}

return View();


}

生活太矮!!在一条没有尽头的路上,我们低头奔跑···
原文地址:https://www.cnblogs.com/shenghuotaiai/p/7827877.html