能否将"列标题映射的默认命名约定"作用于Excel导出
VAllens opened this issue · comments
Allen commented
能否在没有自定义映射规则的情况下,将"列标题映射的默认命名约定"作用于Excel导出。
举例:
我没有调用Map<TModel>(parameters...)
,但我希望导出后,
DisplayNameProperty
属性在Excel表格中显示的列名是Display Name
,而不是DisplayNameProperty
。
而ColumnNameAttributeProperty属性
在Excel表格中的列名是正确显示的——By Name
。
换句话说,在导出功能中,ColumnAttribute
起作用了,但DisplayAttribute
没起作用。
实体类SampleClass
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Npoi.Mapper.Attributes;
namespace Sample
{
public class SampleClass
{
public string StringProperty { get; set; }
[Column("By Name")]
public string ColumnNameAttributeProperty { get; set; }
[Column(11)]
public string ColumnIndexAttributeProperty { get; set; }
[Ignore]
public string IgnoredAttributeProperty { get; set; }
[Display(Name = "Display Name")]
public string DisplayNameProperty { get; set; }
[Column(CustomFormat = "0%")]
public double CustomFormatProperty { get; set; }
}
}
Donny Tian commented
建议还是用ColumnAttribute或者用Map方法, DisplayAttribute的import支持做的比较早, 但后来感觉其意义比较容易和其他业务逻辑功能混淆, 所以后来的功能尽量不再使用它了, 导致目前export的时候没有考虑它.
Allen commented
Hi, 我觉得,在读取属性的特性时,可以优先判断是否ColumnAttribute
,如果没有ColumnAttribute
再判断DisplayAttribute
,其次是当用户调用Map<T>()
覆盖你事先解析和缓存。 Import
和Export
都可以