EPPlus属性总计行

2022-01-30 15:07:58 标签 c#asp.net-core-mvcepplusasp.net-core-5.0

我遵循这里的示例,使用属性创建总计行。尽管遵循了确切的例子(只是我的模型改变了),我仍然无法获得总计行。

我的视图模型:

[EpplusTable(AutofitColumns = true, PrintHeaders = true, AutoCalculate = true, ShowTotal = true, ShowFirstColumn = true, ShowLastColumn = true)]
[
    EpplusFormulaTableColumn(Order = 11, NumberFormat = "0.00", Header = "Net Total", Formula = "J2-K2", TotalsRowFunction = RowFunctions.Sum, TotalsRowNumberFormat = "0.00")
]
public class SetReportVM
{
    [EpplusTableColumn(Order = 0, Header = "Sr. No.", NumberFormat = "#")]
    public int SerialNo { get; set; }
    [EpplusTableColumn(Order = 1, Header = "Tran Date", NumberFormat = "dd/MM/yyyy")]
    public DateTime TranDate { get; set; }
    [EpplusTableColumn(Order = 2, Header = "Track Id", NumberFormat = "@")]
    public string TrackId { get; set; }
    [EpplusTableColumn(Order = 3, Header = "Tran Message Id", NumberFormat = "@")]
    public string TranMessageId { get; set; }
    [EpplusTableColumn(Order = 4, Header = "Action Code", NumberFormat = "@")]
    public string ActionCode { get; set; }
    [EpplusTableColumn(Order = 5, Header = "Auth Code", NumberFormat = "@")]
    public string AuthCode { get; set; }
    [EpplusTableColumn(Order = 6, Header = "CardHolder Name", NumberFormat = "@")]
    public string CardHolderName { get; set; }
    [EpplusTableColumn(Order = 7, Header = "Masked Card Number", NumberFormat = "@")]
    public string CardNumber { get; set; }
    [EpplusTableColumn(Order = 8, NumberFormat = "@")]
    public string Currency { get; set; }
    [EpplusTableColumn(Order = 9, NumberFormat = "0.00", TotalsRowFunction = RowFunctions.Sum, TotalsRowNumberFormat = "0.00")]
    public decimal Amount { get; set; }
    [EpplusTableColumn(Order = 10, Header = "Interchange Fees", NumberFormat = "0.00", TotalsRowFunction = RowFunctions.Sum, TotalsRowNumberFormat = "0.00")]
    public decimal InterchangeFees { get; set; }
}

Then in my controller Method;

var SettlementRecords = (from v in _context.VistaReports
                            join m in _context.Merchants
                            on v.MerchantRefId equals m.Id
                            where v.MerchantRefId == exportRecordsVM.MerchantRefId &&
                                    (v.TranDate >= exportRecordsVM.DateFrom && v.TranDate <= exportRecordsVM.DateTo)
                                    && v.Result == "SUCCESS" && v.TerminalRefId==Terminal.Id && v.ActionCode == "1 - Purchase"
                            select new SetReportVM()
                            {
                                TranMessageId = v.TranMessageId,
                                TrackId = v.TrackId,
                                AuthCode = v.AuthCode,
                                ActionCode = v.ActionCode,
                                Amount = v.Amount,
                                Currency = v.Currency,
                                TranDate = v.TranDate,
                                CardHolderName = v.CardHolderName,
                                CardNumber = v.CardNumber,
                                InterchangeFees = (m.ICommissionType == 0 ? m.ICommission : (m.ICommission / v.Amount) * 100)
                            }).ToList();
using (var pck = new ExcelPackage())
{
    var sheet = pck.Workbook.Worksheets.Add("sheet");
    sheet.Cells["A1"].LoadFromCollection(SettlementRecords);
    string fileName = Path.Combine("./Reports", "PGW_Settlement_" + Terminal.TerminalId + "_" + exportRecordsVM.DateFrom.ToString("yyyyMMdd") + exportRecordsVM.DateTo.ToString("yyyyMMdd") + ".csv");
    var file = new FileStream(@fileName, FileMode.Create);
    sheet.Cells[1, 1, sheet.Dimension.End.Row, sheet.Dimension.End.Column].SaveToText(file, new ExcelOutputTextFormat());
    file.Close();
}

有谁知道该怎么做吗?

阅读全文

▼ 版权说明

相关文章也很精彩
推荐内容
更多标签
相关热门
全站排行
随便看看

错说 cuoshuo.com —— 程序员的报错记录

部分内容根据CC版权协议转载;网站内容仅供参考,生产环境使用务必查阅官方文档

辽ICP备19011660号-5

×

扫码关注公众号:职场神器
发送: 1
获取永久解锁本站全部文章的验证码