From 5ab2da3c3daf94c009a2b455d3ec8832475c96b5 Mon Sep 17 00:00:00 2001 From: qi_0527 Date: Sat, 9 Nov 2024 20:17:51 +0800 Subject: [PATCH] Second upload --- .../Yuntech_in_car_tableController.cs | 36 ++++++++++++++----- .../Models/Yuntech_in_car_table.cs | 1 + 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs b/WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs index 2705dec..7bc41d4 100644 --- a/WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs +++ b/WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs @@ -43,6 +43,7 @@ namespace Parking_space_WebAPI.Controllers in_time = c.in_time, out_time = c.out_time, location = c.location, + out_location=c.out_location, } ).ToListAsync(); @@ -244,7 +245,7 @@ namespace Parking_space_WebAPI.Controllers return location_name_table; } #endregion - + #region 新增資料 /// @@ -704,7 +705,6 @@ namespace Parking_space_WebAPI.Controllers /// 起始時間 /// 結束時間 /// - [HttpGet("location_name_2_-{id}-start_time-{start_time}-end_time-{end_time}-export_excel")] public async Task ExportYuntech_in_car_table_date_to_excel(string id, DateTime start_time, DateTime end_time) { @@ -731,14 +731,22 @@ namespace Parking_space_WebAPI.Controllers worksheet.Cells["C1"].Value = "進入時間"; worksheet.Cells["D1"].Value = "出去時間"; + // 設置列寬 + worksheet.Column(1).Width = 20; + worksheet.Column(2).Width = 15; + worksheet.Column(3).Width = 25; + worksheet.Column(4).Width = 25; + // 添加資料 int row = 2; foreach (var item in in_car_table) { worksheet.Cells["A" + row].Value = item.location; worksheet.Cells["B" + row].Value = item.license_plate_number; - worksheet.Cells["C" + row].Value = item.in_time.ToString(); // 可以自行調整日期時間的格式 - worksheet.Cells["D" + row].Value = item.out_time?.ToString(); + worksheet.Cells["C" + row].Value = item.in_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? ""; + worksheet.Cells["D" + row].Value = item.out_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? ""; + + row++; } @@ -752,6 +760,7 @@ namespace Parking_space_WebAPI.Controllers } #endregion + #region 自動生成時間段Excel文件 /// /// 自動生成包含時間範圍內車輛資料的 Excel 文件 @@ -788,15 +797,19 @@ namespace Parking_space_WebAPI.Controllers worksheet.Cells["B1"].Value = "車牌號碼"; worksheet.Cells["C1"].Value = "進入時間"; worksheet.Cells["D1"].Value = "出去時間"; - + // 設置列寬 + worksheet.Column(1).Width = 20; + worksheet.Column(2).Width = 15; + worksheet.Column(3).Width = 25; + worksheet.Column(4).Width = 25; // 添加資料 int row = 2; foreach (var item in in_car_table) { worksheet.Cells["A" + row].Value = item.location; worksheet.Cells["B" + row].Value = item.license_plate_number; - worksheet.Cells["C" + row].Value = item.in_time.ToString(); // 可以自行調整日期時間的格式 - worksheet.Cells["D" + row].Value = item.out_time.ToString(); + worksheet.Cells["C" + row].Value = item.in_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? ""; + worksheet.Cells["D" + row].Value = item.out_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? ""; row++; } @@ -840,6 +853,11 @@ namespace Parking_space_WebAPI.Controllers worksheet.Cells["B1"].Value = "車牌號碼"; worksheet.Cells["C1"].Value = "進入時間"; worksheet.Cells["D1"].Value = "出去時間"; + // 設置列寬 + worksheet.Column(1).Width = 20; + worksheet.Column(2).Width = 15; + worksheet.Column(3).Width = 25; + worksheet.Column(4).Width = 25; // 添加資料 int row = 2; @@ -847,8 +865,8 @@ namespace Parking_space_WebAPI.Controllers { worksheet.Cells["A" + row].Value = item.location; worksheet.Cells["B" + row].Value = item.license_plate_number; - worksheet.Cells["C" + row].Value = item.in_time.ToString(); // 可以自行調整日期時間的格式 - worksheet.Cells["D" + row].Value = item.out_time.ToString(); + worksheet.Cells["C" + row].Value = item.in_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? ""; + worksheet.Cells["D" + row].Value = item.out_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? ""; row++; } diff --git a/WebApi_data_value/Models/Yuntech_in_car_table.cs b/WebApi_data_value/Models/Yuntech_in_car_table.cs index ef87a74..d6127a4 100644 --- a/WebApi_data_value/Models/Yuntech_in_car_table.cs +++ b/WebApi_data_value/Models/Yuntech_in_car_table.cs @@ -8,5 +8,6 @@ public string? location { get; set; } public DateTime? in_time { get; set; } public DateTime? out_time { get; set; } + public string? out_location { get; set; } } }