public ActionResult ExportByPersonal() { ExportByPersonalArgs args = base.RequestArgs <ExportByPersonalArgs>(); FileInfo fileInfo = new FileInfo(ExcelHelper.ExportPersonal(_environment.ContentRootPath, args)); return(this.RespondDataResult(fileInfo.Name)); }
public ActionResult ExportByPersonal() { ExportByPersonalArgs args = base.RequestArgs <ExportByPersonalArgs>(); FileInfo fileInfo = new FileInfo(ExcelHelper.ExportPersonal(base.Server.MapPath("/"), args)); return(this.RespondDataResult(fileInfo.Name)); }
public async ValueTask <ActionResult> ExportByPersonalAsync() { ExportByPersonalArgs args = base.RequestArgs <ExportByPersonalArgs>(); var filePath = await ExcelHelper.ExportPersonalAsync(_environment.ContentRootPath, args); FileInfo fileInfo = new FileInfo(filePath); return(this.RespondDataResult(fileInfo.Name)); }
public static string ExportPersonal(string rootPath, ExportByPersonalArgs args) { List <WeeklyReport> arg_2E_0 = ExcelHelper._weeklyReportManager.GetWeeklyReportListByPerson(args.User, args.StartYear, args.StartMonth, args.EndYear, args.EndMonth); List <WeeklyReport> list = new List <WeeklyReport>(); foreach (WeeklyReport current in arg_2E_0) { foreach (ExportByPersonalItem current2 in args.ExportItemList) { if (current.Year == current2.Year && current.WeekOfYear == current2.WeekOfYear) { list.Add(current); break; } } } if (list.Count == 0) { return(null); } IWorkbook workbook = null; FileStream fileStream = null; string text = Path.Combine(rootPath, ExcelHelper._templateFile); FileStream fileStream2 = new FileStream(text, FileMode.Open, FileAccess.Read, FileShare.Read); if (text.IndexOf(".xlsx") > 0) { workbook = new XSSFWorkbook(fileStream2); } else if (text.IndexOf(".xls") > 0) { workbook = new HSSFWorkbook(fileStream2); } ISheet sheet = null; string text3; try { sheet = workbook.GetSheetAt(0); string text2 = list[0].Monday.ToString("yyyyMMdd") + "-"; text2 += list[list.Count - 1].Sunday.ToString("yyyyMMdd"); text2 += "-"; User user = ExcelHelper._userManager.GetUser(args.User); text2 += user.Name; text2 += "-周报"; sheet.GetRow(0).GetCell(0).SetCellValue(text2); ICellStyle cellStyle = workbook.CreateCellStyle(); cellStyle.BorderBottom = BorderStyle.Thin; cellStyle.BorderLeft = BorderStyle.Thin; cellStyle.BorderRight = BorderStyle.Thin; cellStyle.BorderTop = BorderStyle.Thin; cellStyle.VerticalAlignment = VerticalAlignment.Center; cellStyle.WrapText = true; int num = 2; foreach (WeeklyReport current3 in list) { int firstRow = num; foreach (WeeklyReportItem current4 in current3.ItemList) { IRow expr_234 = sheet.CreateRow(num); expr_234.Height = 350; expr_234.CreateCell(0).SetCellValue(current3.Monday.ToString("yyyyMMdd") + "-" + current3.Sunday.ToString("yyyyMMdd")); expr_234.CreateCell(1).SetCellValue(current4.OrganizationName); expr_234.CreateCell(2).SetCellValue(current3.UserName); expr_234.CreateCell(3).SetCellValue(current4.WorkTypeName); expr_234.CreateCell(4).SetCellValue(current4.WorkTaskName); expr_234.CreateCell(5).SetCellValue(current4.Content.Replace("<br/>", "\r\n")); expr_234.CreateCell(6).SetCellValue(current4.StatusName); ICell cell = expr_234.CreateCell(7); if (current4.Date.HasValue) { cell.SetCellValue(current4.Date.Value.ToString("yyyy-MM-dd")); } using (List <ICell> .Enumerator enumerator4 = expr_234.Cells.GetEnumerator()) { while (enumerator4.MoveNext()) { enumerator4.Current.CellStyle = cellStyle; } } num++; } CellRangeAddress region = new CellRangeAddress(firstRow, num - 1, 0, 0); sheet.AddMergedRegion(region); region = new CellRangeAddress(firstRow, num - 1, 1, 1); sheet.AddMergedRegion(region); region = new CellRangeAddress(firstRow, num - 1, 2, 2); sheet.AddMergedRegion(region); } text3 = Path.Combine(rootPath, "ExcelExport", text2 + "(" + DateTime.Now.ToString("ddHHmmss") + ").xls"); fileStream = new FileStream(text3, FileMode.OpenOrCreate, FileAccess.Write); workbook.Write(fileStream); } catch (Exception arg_440_0) { throw arg_440_0; } finally { fileStream2.Close(); fileStream2.Dispose(); if (fileStream != null) { fileStream.Flush(); fileStream.Close(); fileStream.Dispose(); } } return(text3); }