[성현모] 개선
This commit is contained in:
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<Routes />
|
<Routes />
|
||||||
|
<script src="js/script.js"></script>
|
||||||
<script src="_framework/blazor.web.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>
|
<script src="_content/Radzen.Blazor/Radzen.Blazor.js?v=@(typeof(Radzen.Colors).Assembly.GetName().Version)"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
@using System.Collections.Concurrent
|
@using System.Collections.Concurrent
|
||||||
@using System.Collections.Specialized
|
@using System.Collections.Specialized
|
||||||
@using System.Collections
|
@using System.Collections
|
||||||
|
@using ClosedXML.Excel
|
||||||
@using Web.Tra.Services
|
@using Web.Tra.Services
|
||||||
@inject CPXV2LogService CPXV2LogService
|
@inject CPXV2LogService CPXV2LogService
|
||||||
@inject PopupService PopupService
|
@inject PopupService PopupService
|
||||||
@ -590,6 +591,50 @@
|
|||||||
|
|
||||||
private async Task OnExportExcel()
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,6 +3,7 @@
|
|||||||
public enum EnumTabs
|
public enum EnumTabs
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
|
Global = 1,
|
||||||
|
|
||||||
OverviewC1 = 10,
|
OverviewC1 = 10,
|
||||||
OverviewC1Merged = 11,
|
OverviewC1Merged = 11,
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="ClosedXML" Version="0.105.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="Radzen.Blazor" Version="7.3.2" />
|
<PackageReference Include="Radzen.Blazor" Version="7.3.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
8
Projects/WebClient/Web.Tra/wwwroot/js/script.js
Normal file
8
Projects/WebClient/Web.Tra/wwwroot/js/script.js
Normal 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);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user