/// <summary> /// 导出试题信息 /// </summary> /// <param name="UnitId"></param> /// <returns></returns> public int QuestionExport(int UnitId) { List <BackQuestionBank> list = question.GetListByUnitId(UnitId); IWorkbook workbook = new XSSFWorkbook(); ISheet sheet = workbook.CreateSheet("QuestionBank"); var type = typeof(BackQuestionBank); IRow row = sheet.CreateRow(0); int column = 0; int rows = 1; foreach (var item in type.GetProperties()) { row.CreateCell(column).SetCellValue(item.Name); ++column; } foreach (var item in list) { row = sheet.CreateRow(rows); row.CreateCell(0).SetCellValue(rows); row.CreateCell(1).SetCellValue(item.Question); row.CreateCell(2).SetCellValue(item.QuestionType); row.CreateCell(3).SetCellValue(item.UnitId); row.CreateCell(4).SetCellValue(item.A); row.CreateCell(5).SetCellValue(item.B); row.CreateCell(6).SetCellValue(item.C); row.CreateCell(7).SetCellValue(item.D); row.CreateCell(8).SetCellValue(item.ChoiceAnswer); row.CreateCell(9).SetCellValue(item.JudgeAnswer); ++rows; } string path = Server.MapPath("/QuestionBankExprot/"); string filename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"; using (var fs = System.IO.File.OpenWrite(path + filename)) { workbook.Write(fs); } Users us = (Users)Session["User"]; if (list.Count == (rows - 1)) { logs.Add(us.ID, "导出试题", 1); } else { logs.Add(us.ID, "导出试题", 0); } return(rows); }