[성현모] 개선

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

@ -16,6 +16,7 @@
<body>
<Routes />
<script src="js/script.js"></script>
<script src="_framework/blazor.web.js"></script>
<script src="_content/Radzen.Blazor/Radzen.Blazor.js?v=@(typeof(Radzen.Colors).Assembly.GetName().Version)"></script>
</body>

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

View File

@ -3,6 +3,7 @@
public enum EnumTabs
{
None = 0,
Global = 1,
OverviewC1 = 10,
OverviewC1Merged = 11,

View File

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.105.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Radzen.Blazor" Version="7.3.2" />
</ItemGroup>

View File

@ -0,0 +1,8 @@
window.downloadFile = (fileName, base64Data) => {
const link = document.createElement('a');
link.download = fileName;
link.href = "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," + base64Data;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};