private void SetSampleCell(ExcelRange range, string value, ShiftType?type) { range.Value = value; SetColor(range, Shift.GetColor(type)); }
public void WritetoFile() { var name = OutputPath == string.Empty ? string.Format(OutputName, CurrentDate.ToString().Replace("/", "-")) : string.Format(OutputPath + "/" + OutputName, CurrentDate.ToString().Replace("/", "-")); FileInfo output = new FileInfo(name); ExcelWorksheet worksheet; if (output.Exists) { output.Delete(); } using (ExcelPackage package = new ExcelPackage(output)) { try { int startI = 1; int startJ = 2; worksheet = package.Workbook.Worksheets.Add("تعداد تماسهای خارجی"); var start = StartObservation; var end = EndObservation; int j = startJ; while (start < end) { worksheet.Cells[startI, j].Value = start.ToString(@"hh\:mm"); j++; start = start.Add(Duration); } int i = startI + 1; foreach (var employee in Employees) { j = startJ; var list = OutboundCountList[employee.Number]; worksheet.Cells[i, j - 1].Value = employee.Number; foreach (var item in list) { if (item.Count != 0) { worksheet.Cells[i, j].Value = item.Count; SetColor(worksheet.Cells[i, j], Shift.GetColor(item.Type)); } j++; } i++; } //worksheet.Cells[2, 3, 2, 5].Merge = true; //worksheet.Cells[2, 3, 2, 5].Value = string.Format("روز: {0}", CurrentDate.ToString()); SetColor(worksheet.Cells[startI, startJ - 1, startI, j - 1], Color.LightGray); SetColor(worksheet.Cells[startI, startJ - 1, startI + Employees.Count, startJ - 1], Color.LightGray); SetBorder(worksheet.Cells[startI + Employees.Count + 2, startJ - 1, startI + Employees.Count + 4, startJ - 1]); SetSampleCell(worksheet.Cells[startI + Employees.Count + 2, startJ - 1], "Reyhoon", ShiftType.D); SetSampleCell(worksheet.Cells[startI + Employees.Count + 3, startJ - 1], "Other Shifts", ShiftType.None); SetSampleCell(worksheet.Cells[startI + Employees.Count + 4, startJ - 1], "None", null); SetBorder(worksheet.Cells[startI, startJ - 1, startI + Employees.Count, j - 1]); //SetBorder(worksheet.Cells[2, 3, 2, 5]); worksheet.View.RightToLeft = true; worksheet.Cells.Style.ReadingOrder = ExcelReadingOrder.RightToLeft; worksheet.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; worksheet.Cells.Style.VerticalAlignment = ExcelVerticalAlignment.Center; package.Save(); } catch (Exception e) { throw new Exception("Error in writing output File\n" + e.Message); } } }