fix 优化导出处理

This commit is contained in:
2025-04-22 14:21:03 +08:00
parent 6198e4bb8e
commit fc4abae3b2
3 changed files with 5 additions and 3 deletions

View File

@@ -5,12 +5,12 @@ namespace Dlhis.ExcelHelper;
public static class ExcelExtensions
{
public static async Task<byte[]> ToExcelBytesAsync<T>(this List<T> data) where T : IExcelExportable
public static async Task<byte[]> ToExcelBytesAsync<T>(this List<T> data)
{
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
var type = typeof(T);
var sheetName = type.GetCustomAttribute<ExcelAttribute>()!.Description;
var sheetName = type.GetCustomAttribute<ExcelAttribute>()?.Description ?? type.Name;
var excelHeaderNames = type.GetProperties().Where(x => x.IsDefined(typeof(ExcelAttribute))).ToList();
using var package = new ExcelPackage();