aspose导入(mvc)
[HttpPost] public ActionResult ImportTaskItem() { if (Request.Files != null) { try { HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; foreach (string key in files) { HttpPostedFile file1 = files[key]; bool exportColumnName = true; Workbook workbook = new Workbook(file1.InputStream); Worksheet worksheet = workbook.Worksheets[0]; Cells cells = worksheet.Cells; string titleformat = "检查项目,检查内容,具体检查项,检查方式"; string title = ""; for (int j = 0; j < cells.MaxDataColumn + 1; j++) { title += cells[0, j].StringValue.Trim() + ','; } if (title.Substring(0, title.Length - 1) != titleformat) { return Json(new { success = false, message = "文件格式不符合,请检查后在导入!" }); } else { var data = cells.ExportDataTableAsString(0, 0, cells.MaxDataRow + 1, cells.MaxDataColumn + 1, exportColumnName); List<bs_inspect_item> itemlist = new List<bs_inspect_item>(); int column = 1; foreach (DataRow item in data.Rows) { bs_inspect_item inspectitem = new bs_inspect_item(); inspectitem.id = Guid.NewGuid().ToString(); inspectitem.item_name = item["检查项目"].ToString().Trim(); inspectitem.content = item["检查内容"].ToString().Trim(); inspectitem.detail_content = item["具体检查项"].ToString().Trim(); inspectitem.inspect_mode = item["检查方式"].ToString().Trim(); inspectitem.unit_id = UserState.unitId; inspectitem.disable = "0"; inspectitem.sort = column; itemlist.Add(inspectitem); column++; } _baseSetService.ExcelRedeiSet(itemlist, UserState.userId); } } return Json(new { success = true }); } catch (Exception ex) { return Json(new { success = false, content = "导入Excel失败!" }); } } return Json(new { success = false, content = "文件为空!" });