รายงานลงเวลา ปรับให้การแสดงผลเหมือนเดิมก่อนแก้ไข #1815
Some checks failed
release-dev / release-dev (push) Failing after 12s

เปลี่ยนจากโหลดโดยตรงเป็นผ่านโคลนจากtemplate
This commit is contained in:
harid 2025-09-30 15:00:02 +07:00
parent 373e2a06d8
commit edbd337ab6
2 changed files with 20 additions and 16 deletions

View file

@ -11,6 +11,7 @@ using BMA.EHR.Domain.Shared;
using BMA.EHR.Leave.Service.DTOs.Reports;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing.Template;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OfficeOpenXml;
@ -2157,12 +2158,15 @@ 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())
var templatePath = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", "TimeStampRecords.xlsx");
byte[] templateBytes = System.IO.File.ReadAllBytes(templatePath);
//using (var package = new ExcelPackage(fileInfo))
using (var stream = new MemoryStream(templateBytes))
using (var package = new ExcelPackage(stream))
{
//var worksheet = package.Workbook.Worksheets[0];
var worksheet = package.Workbook.Worksheets.Add("Sheet1");
//var worksheet = package.Workbook.Worksheets.Add("Sheet1");
var worksheet = package.Workbook.Worksheets["Sheet1"] ?? package.Workbook.Worksheets[0];
worksheet.Cells["A1:J1"].Merge = true;
worksheet.Cells["A2:J2"].Merge = true;
@ -2174,7 +2178,7 @@ namespace BMA.EHR.Leave.Service.Controllers
range.Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center;
range.Style.Font.Bold = true;
}
worksheet.Cells[1, 1].Value = "แบบการลงเวลาปฏิบัติราชการ";
//worksheet.Cells[1, 1].Value = "แบบการลงเวลาปฏิบัติราชการ";
worksheet.Cells[2, 1].Value = organizationName;
worksheet.Cells[3, 1].Value = dateTimeStamp;
@ -2188,16 +2192,16 @@ namespace BMA.EHR.Leave.Service.Controllers
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 = "หมายเหตุ";
//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)
{