我有一个 MVC 应用程序,我在其中使用 CsvHelper 以允许用户在 excel 中导出报告数据。我想更改导出文件中某些列标题的值。在报告模型中,我已经定义了这样的属性
public string DateSection1Finished { get; set; }
public string TimeSection1Finished { get; set; }
public string DateSection2Finished { get; set; }
public string TimeSection2Finished { get; set; }
当前输出的 Excel 示例
现在,如果我更改属性的值并更新我的代码库中的所有引用,我可以在 excel 文档中看到列标题名称被更新。但是,我想知道是否可以在属性上方使用属性并将其映射到 excel 文件输出中的标题值
[System.ComponentModel.DataAnnotations.Display(Name = "NewColumnHeaderName")]
public string DateSection1Finished { get; set; }
所需输出的 Excel 示例