[성현모] 개선

This commit is contained in:
SHM
2025-09-25 09:44:09 +09:00
parent 681f1e97f4
commit 5fa3717a37
5 changed files with 57 additions and 1 deletions

View File

@ -4,6 +4,7 @@
@using System.Collections.Concurrent
@using System.Collections.Specialized
@using System.Collections
@using ClosedXML.Excel
@using Web.Tra.Services
@inject CPXV2LogService CPXV2LogService
@inject PopupService PopupService
@ -590,6 +591,50 @@
private async Task OnExportExcel()
{
var tab = Tabs.FirstOrDefault(x => x.Key.Id == SelectedTabIndex);
if(tab.Value?.Count > 0)
{
if (tab.Key.EnumTab == EnumTabs.OverviewC1 || tab.Key.EnumTab == EnumTabs.OverviewC1Detail || tab.Key.EnumTab == EnumTabs.OverviewC1Merged || tab.Key.EnumTab == EnumTabs.OverviewC1DetailMerged)
await ExportToExcelAsync(tab.Value.Cast<Overview>());
if(tab.Key.EnumTab == EnumTabs.TestSummaryC1)
await ExportToExcelAsync(tab.Value.Cast<ParseTestSummary>());
}
}
public async Task ExportToExcelAsync<T>(IEnumerable<T> data, string fileName = "export.xlsx")
{
using var workbook = new XLWorkbook();
var worksheet = workbook.Worksheets.Add("Sheet1");
var properties = typeof(T).GetProperties();
// 헤더
for (int i = 0; i < properties.Length; i++)
{
worksheet.Cell(1, i + 1).Value = properties[i].Name;
}
// 데이터
int row = 2;
foreach (var item in data)
{
for (int col = 0; col < properties.Length; col++)
{
var value = properties[col].GetValue(item);
// if(value is int)
// worksheet.Cell(row, col + 1).Value = Convert.ToInt32(value);
// else if (value is double)
// worksheet.Cell(row, col + 1).Value = Convert.ToDouble(value);
worksheet.Cell(row, col + 1).Value = $" {value}";
}
row++;
}
using var stream = new MemoryStream();
workbook.SaveAs(stream);
var bytes = stream.ToArray();
await JS.InvokeVoidAsync("downloadFile", fileName, Convert.ToBase64String(bytes));
}
}