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

@@ -92,6 +92,7 @@ public class BalancesController : ControllerBase
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
[ExcelResult("营业点消费明细")] [ExcelResult("营业点消费明细")]
[AllowAnonymous]
[HttpGet("recordPageDetails/export")] [HttpGet("recordPageDetails/export")]
public async Task<List<BalanceRecordDetailPageResponse>> RecordPageDetailsToExportAsync([FromQuery] BalanceRecordPageDetailRequest request) public async Task<List<BalanceRecordDetailPageResponse>> RecordPageDetailsToExportAsync([FromQuery] BalanceRecordPageDetailRequest request)
{ {

View File

@@ -25,7 +25,8 @@ public class BalanceRecordByBusinessPlaceResponse
public Pagination<BalanceRecordDetailPageResponse> Pagination { get; set; } public Pagination<BalanceRecordDetailPageResponse> Pagination { get; set; }
} }
public class BalanceRecordDetailPageResponse [Excel("BalanceRecordDetail")]
public class BalanceRecordDetailPageResponse : IExcelExportable
{ {
public long Id { get; set; } public long Id { get; set; }

View File

@@ -5,12 +5,12 @@ namespace Dlhis.ExcelHelper;
public static class ExcelExtensions 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; ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
var type = typeof(T); 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(); var excelHeaderNames = type.GetProperties().Where(x => x.IsDefined(typeof(ExcelAttribute))).ToList();
using var package = new ExcelPackage(); using var package = new ExcelPackage();