public IActionResult Export(TimeSheetIndexVM request, string SelectedFormat) { SaveOptions options = FileExportHelper.GetSaveOptions(SelectedFormat); byte[] content = timeSheetsService.ExportTimeSheet(request, SelectedFormat); return(File(content, options.ContentType, "Export-TimeSheet." + SelectedFormat.ToLower())); }
public IActionResult Export(AuditFileExportVM request, string SelectedFormat) { SaveOptions options = FileExportHelper.GetSaveOptions(SelectedFormat); byte[] content = auditFilesService.ProcessExport(request, SelectedFormat); return(File(content, options.ContentType, "Export-AuditFiles." + SelectedFormat.ToLower())); }
private string GetTempFileName(string tempFileName) { string tempProjectFolder = FolderHelper.GetCurrentProjectTaskResultFolder(); string name = FileExportHelper.GetExportFileName(tempFileName); string suffix = string.Empty; int index = 0; while (File.Exists(Path.Combine(tempProjectFolder, name + "_" + index.ToString()))) { index++; suffix = string.Concat(new object[] { "_(", index.ToString(), ")" }); } return(name += suffix); }
public byte[] ExportTimeSheet(TimeSheetIndexVM request, string SelectedFormat) { var VM = new TimeSheetIndexVM { SearchRequest = new Model.Requests.TimeSheetSearchRequest() { Year = request?.SearchRequest?.Year ?? DateTime.Today.Year, Months = request?.SearchRequest?.Months ?? new List <int> { DateTime.Today.Month } } }; if (request.SearchRequest?.UserIDs != null && request.SearchRequest.UserIDs.Count > 0) { VM.SearchRequest.UserIDs = request.SearchRequest.UserIDs; } LoadSelectListData(VM); VM.TimeSheet = timeSheetsAPIService.GetTimeSheets(VM.SearchRequest); var book = new ExcelFile(); var sheet = book.Worksheets.Add("Sheet1"); CellStyle style = sheet.Rows[0].Style; style.Font.Weight = ExcelFont.BoldWeight; style.HorizontalAlignment = HorizontalAlignmentStyle.Center; sheet.Columns[0].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center; sheet.Columns[0].SetWidth(50, LengthUnit.Pixel); sheet.Columns[1].SetWidth(120, LengthUnit.Pixel); sheet.Cells["A1"].Value = "Day"; sheet.Cells["B1"].Value = "Type"; sheet.Cells["C1"].Value = "Start Time"; sheet.Cells["D1"].Value = "End Time"; sheet.Cells["E1"].Value = "Break"; sheet.Cells["F1"].Value = "Work Time"; sheet.Cells["G1"].Value = "M³"; sheet.Cells["H1"].Value = "Km - stand"; sheet.Cells["I1"].Value = "Privat"; sheet.Cells["J1"].Value = "Fuel"; sheet.Cells["K1"].Value = "AdBlue"; sheet.Cells["L1"].Value = "Notes"; for (int r = 1; r <= VM.TimeSheet.Count; r++) { var item = VM.TimeSheet[r - 1]; sheet.Cells[r, 0].Value = item.DayNo; sheet.Cells[r, 1].Value = item.DayType.GetDescription(); if (item.DayType == DayType.WorkDay || item.DayType == DayType.TimeConsumption) { sheet.Cells[r, 2].Value = item.StartTimeStr; sheet.Cells[r, 3].Value = item.EndTimeStr; sheet.Cells[r, 4].Value = item.BreakTimeStr; } sheet.Cells[r, 5].Value = item.WorkTime; sheet.Cells[r, 6].Value = item.MetersSquared; sheet.Cells[r, 7].Value = item.KmStand; sheet.Cells[r, 8].Value = item.PrivatTanken; sheet.Cells[r, 9].Value = item.Fuel; sheet.Cells[r, 10].Value = item.AdBlue; sheet.Cells[r, 11].Value = item.AdBlue; } SaveOptions options = FileExportHelper.GetSaveOptions(SelectedFormat); using (var stream = new MemoryStream()) { book.Save(stream, options); return(stream.ToArray()); } }
public byte[] ProcessExport(AuditFileExportVM request, string SelectedFormat) { var VM = new AuditFileExportVM { SearchRequest = new Model.Requests.AuditFileSearchRequest() { Year = request?.SearchRequest?.Year ?? DateTime.Today.Year, Months = request?.SearchRequest?.Months ?? new List <int> { DateTime.Today.Month } } }; if (request.SearchRequest?.UserIDs != null && request.SearchRequest.UserIDs.Count > 0) { VM.SearchRequest.UserIDs = request.SearchRequest.UserIDs; } LoadSelectListData(VM); VM.AuditFiles = auditFilesAPIService.GetAuditFiles(VM.SearchRequest); var book = new ExcelFile(); var sheet = book.Worksheets.Add("Sheet1"); CellStyle style = sheet.Rows[0].Style; style.Font.Weight = ExcelFont.BoldWeight; style.HorizontalAlignment = HorizontalAlignmentStyle.Center; sheet.Columns[0].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center; sheet.Columns[0].SetWidth(120, LengthUnit.Pixel); sheet.Columns[2].SetWidth(80, LengthUnit.Pixel); sheet.Columns[3].SetWidth(70, LengthUnit.Pixel); sheet.Columns[4].SetWidth(70, LengthUnit.Pixel); sheet.Columns[5].SetWidth(150, LengthUnit.Pixel); sheet.Columns[6].SetWidth(110, LengthUnit.Pixel); sheet.Cells["A1"].Value = "TimeSheet KEY"; sheet.Cells["B1"].Value = "DayNo"; sheet.Cells["C1"].Value = "Field"; sheet.Cells["D1"].Value = "Old Value"; sheet.Cells["E1"].Value = "New Value"; sheet.Cells["F1"].Value = "Date&Time of Change"; sheet.Cells["G1"].Value = "Changed by User"; for (int r = 1; r <= VM.AuditFiles.Count; r++) { var item = VM.AuditFiles[r - 1]; sheet.Cells[r, 0].Value = item.TimeSheet.TimeSheetKey; sheet.Cells[r, 1].Value = item.TimeSheet.DayNo; sheet.Cells[r, 2].Value = item.FieldStr; sheet.Cells[r, 3].Value = item.OldValueStr; sheet.Cells[r, 4].Value = item.NewValueStr; sheet.Cells[r, 5].Value = item.DateChangedStr; sheet.Cells[r, 6].Value = item.ChangedByUser.Username; } SaveOptions options = FileExportHelper.GetSaveOptions(SelectedFormat); using (var stream = new MemoryStream()) { book.Save(stream, options); return(stream.ToArray()); } }