Second upload

This commit is contained in:
qi_0527 2024-11-09 20:17:51 +08:00
parent c64eff200c
commit 5ab2da3c3d
2 changed files with 28 additions and 9 deletions

View File

@ -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();
@ -704,7 +705,6 @@ namespace Parking_space_WebAPI.Controllers
/// <param name="start_time">起始時間</param>
/// <param name="end_time">結束時間</param>
/// <returns></returns>
[HttpGet("location_name_2_-{id}-start_time-{start_time}-end_time-{end_time}-export_excel")]
public async Task<IActionResult> 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文件
/// <summary>
/// 自動生成包含時間範圍內車輛資料的 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++;
}

View File

@ -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; }
}
}