fix timestamp report #1843 (#1844)
Some checks failed
release-dev / release-dev (push) Failing after 12s
Some checks failed
release-dev / release-dev (push) Failing after 12s
Co-authored-by: harid <harid_pr61@live.rmutl.com>
This commit is contained in:
parent
1ec8e51c37
commit
7ddc1debfc
2 changed files with 37 additions and 38 deletions
|
|
@ -2168,12 +2168,15 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
|
||||
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.Add("Sheet1");
|
||||
|
||||
var worksheet = package.Workbook.Worksheets["Sheet1"] ?? package.Workbook.Worksheets[0];
|
||||
// กำหนดให้ใช้ฟอนต์ TH SarabunPSK ซึ่งเป็นฟอนต์มาตรฐานราชการไทย
|
||||
// **ข้อควรระวัง:** หากเครื่องผู้ใช้ไม่มีฟอนต์นี้ติดตั้งอยู่ การจัดหน้าเอกสารจะเพี้ยน
|
||||
worksheet.Cells.Style.Font.Name = "TH SarabunPSK";
|
||||
|
||||
worksheet.Cells["A1:J1"].Merge = true;
|
||||
worksheet.Cells["A2:J2"].Merge = true;
|
||||
|
|
@ -2185,56 +2188,50 @@ 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[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)
|
||||
int colCount = 10;
|
||||
int totalRows = employees.Count;
|
||||
|
||||
// เตรียม List<object[]> สำหรับใช้กับ LoadFromArrays
|
||||
var data = new List<object[]>(totalRows);
|
||||
for (int i = 0; i < totalRows; i++)
|
||||
{
|
||||
worksheet.Cells[startRow, 1].Value = emp.no;
|
||||
worksheet.Cells[startRow, 2].Value = emp.fullName;
|
||||
worksheet.Cells[startRow, 3].Value = emp.dutyTimeName;
|
||||
worksheet.Cells[startRow, 4].Value = emp.checkInDate;
|
||||
worksheet.Cells[startRow, 5].Value = emp.checkInLocation;
|
||||
worksheet.Cells[startRow, 6].Value = emp.checkInTime;
|
||||
worksheet.Cells[startRow, 7].Value = emp.checkedOutDate;
|
||||
worksheet.Cells[startRow, 8].Value = emp.checkOutLocation;
|
||||
worksheet.Cells[startRow, 9].Value = emp.checkOutTime;
|
||||
worksheet.Cells[startRow, 10].Value = emp.remark;
|
||||
startRow++;
|
||||
var emp = employees[i];
|
||||
data.Add(new object[]
|
||||
{
|
||||
emp.no,
|
||||
emp.fullName,
|
||||
emp.dutyTimeName,
|
||||
emp.checkInDate,
|
||||
emp.checkInLocation,
|
||||
emp.checkInTime,
|
||||
emp.checkedOutDate,
|
||||
emp.checkOutLocation,
|
||||
emp.checkOutTime,
|
||||
emp.remark
|
||||
});
|
||||
}
|
||||
|
||||
// ใส่กรอบให้ตาราง
|
||||
using (var range = worksheet.Cells[5, 1, startRow - 1, 10])
|
||||
// เขียนข้อมูลลง Excel ครั้งเดียว
|
||||
worksheet.Cells[startRow, 1].LoadFromArrays(data);
|
||||
|
||||
// กำหนดสไตล์ตัวบาง + ขอบ
|
||||
using (var range = worksheet.Cells[startRow, 1, startRow + totalRows - 1, colCount])
|
||||
{
|
||||
range.Style.Font.Bold = false;
|
||||
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;
|
||||
// ส่วนสรุปท้ายตาราง
|
||||
int lastRow = startRow + totalRows + 2;
|
||||
|
||||
worksheet.Cells[lastRow, 2].Value = type.Trim().ToUpper() == "OFFICER" ? "ข้าราชการทั้งหมด" : "ลูกจ้างประจำทั้งหมด";
|
||||
worksheet.Cells[lastRow, 5].Value = profile?.Count;
|
||||
worksheet.Cells[lastRow, 6].Value = "คน";
|
||||
|
|
@ -2260,6 +2257,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
worksheet.Cells[lastRow + 6, 2].Value = "เรียน";
|
||||
worksheet.Cells[lastRow + 7, 2].Value = "เพื่อโปรดทราบ";
|
||||
worksheet.Cells[lastRow + 7, 9].Value = "ทราบ";
|
||||
worksheet.Cells[lastRow + 7, 9].Style.Font.Bold = true;
|
||||
worksheet.Cells[lastRow + 7, 9].Style.Font.Size = 22;
|
||||
worksheet.Cells[lastRow + 8, 2].Value = "................................";
|
||||
worksheet.Cells[lastRow + 8, 9].Value = "................................";
|
||||
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue