From f65dd53cec7e070511c2e98a59b48b2e508485b2 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 25 Aug 2025 10:23:56 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=97=E0=B8=94=E0=B8=AA=E0=B8=AD=E0=B8=9A?= =?UTF-8?q?=20generate=20=E0=B8=95=E0=B8=A3=E0=B8=87=20=E0=B9=84=E0=B8=A1?= =?UTF-8?q?=E0=B9=88=E0=B9=83=E0=B8=8A=E0=B9=89=E0=B9=80=E0=B8=97=E0=B9=87?= =?UTF-8?q?=E0=B8=A1=E0=B9=80=E0=B8=9E=E0=B8=A5=E0=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/LeaveReportController.cs | 60 +++++++++++++++---- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index d1579f86..50949503 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -1962,13 +1962,47 @@ namespace BMA.EHR.Leave.Service.Controllers var org = _userProfileRepository.GetOc(Guid.Parse(req.nodeId), req.node, AccessToken); var organizationName = $"{(!string.IsNullOrEmpty(org.Child4) ? org.Child4 + "/" : "")}{(!string.IsNullOrEmpty(org.Child3) ? org.Child3 + "/" : "")}{(!string.IsNullOrEmpty(org.Child2) ? org.Child2 + "/" : "")}{(!string.IsNullOrEmpty(org.Child1) ? org.Child1 + "/" : "")}{org.Root ?? ""}"; var dateTimeStamp = $"ประจำ ณ วัน{req.StartDate.Date.GetThaiDayOfWeek()} ที่ {req.StartDate.Date.ToThaiShortDate()}{enddate}"; - var template = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", "TimeStampRecords.xlsx"); - FileInfo reportFile = new FileInfo(template); - using (var package = new ExcelPackage(reportFile)) + //var template = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", "TimeStampRecords.xlsx"); + //FileInfo reportFile = new FileInfo(template); + using (var package = new ExcelPackage()) { - var worksheet = package.Workbook.Worksheets[0]; + //var worksheet = package.Workbook.Worksheets[0]; + var worksheet = package.Workbook.Worksheets.Add("Sheet1"); + + worksheet.Cells["A1:J1"].Merge = true; + worksheet.Cells["A2:J2"].Merge = true; + worksheet.Cells["A3:J3"].Merge = true; + + using (var range = worksheet.Cells["A1:J3"]) + { + range.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; + range.Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; + range.Style.Font.Bold = true; + } + worksheet.Cells[1, 1].Value = "แบบการลงเวลาปฏิบัติราชการ"; worksheet.Cells[2, 1].Value = organizationName; worksheet.Cells[3, 1].Value = dateTimeStamp; + + using (var range = worksheet.Cells[4, 1 ,4, 10]) + { + range.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + range.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + range.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + range.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; + range.Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; + range.Style.Font.Bold = true; + } + worksheet.Cells[4, 1].Value = "ลำดับที่"; + worksheet.Cells[4, 2].Value = "ชื่อ - สกุล"; + worksheet.Cells[4, 3].Value = "รอบ"; + worksheet.Cells[4, 4].Value = "วันที่เข้างาน"; + worksheet.Cells[4, 5].Value = "พิกัด"; + worksheet.Cells[4, 6].Value = "เวลามา"; + worksheet.Cells[4, 7].Value = "วันที่ออกงาน"; + worksheet.Cells[4, 8].Value = "พิกัด"; + worksheet.Cells[4, 9].Value = "เวลากลับ"; + worksheet.Cells[4, 10].Value = "หมายเหตุ"; int startRow = 5; foreach (var emp in employees) { @@ -1982,16 +2016,18 @@ namespace BMA.EHR.Leave.Service.Controllers worksheet.Cells[startRow, 8].Value = emp.checkOutLocation; worksheet.Cells[startRow, 9].Value = emp.checkOutTime; worksheet.Cells[startRow, 10].Value = emp.remark; - // ใส่กรอบให้ตาราง - using (var range = worksheet.Cells[startRow, 1, startRow, 10]) - { - range.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; - range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; - range.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; - range.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; - } startRow++; } + + // ใส่กรอบให้ตาราง + using (var range = worksheet.Cells[5, 1, startRow-1, 10]) + { + range.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + range.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + range.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + } + int lastRow = startRow + 2; worksheet.Cells[lastRow, 2].Value = type.Trim().ToUpper() == "OFFICER" ? "ข้าราชการทั้งหมด" : "ลูกจ้างประจำทั้งหมด"; worksheet.Cells[lastRow, 5].Value = profile?.Count;