SimpleExcelWriterAddListT 方法

从 List<T> 写入。数字属性输出为数值单元格,DateTime 属性输出 yyyy-MM-dd 文本。 headers 为 null 时用属性名作表头;否则按顺序使用传入的表头(不要求与属性个数一致)。 withBorder 为 true(默认)时所有单元格加全边框。 返回写入的列数,便于调用 MergeFullRow 计算合并列数。

Definition

命名空间: Suresking.Utility
程序集: Suresking.Utility (在 Suresking.Utility.dll 中) 版本:1.3.22+a27276bb8ffde055e69ff608e98aafba279e1e99
C#
public int AddList<T>(
	IEnumerable<T> list,
	string[]? headers = null,
	bool withBorder = true
)

参数

list  IEnumerableT
数据源;每个元素写入一行。
headers  String  (Optional)
自定义表头;为 null 时使用属性名。
withBorder  Boolean  (Optional)
是否给写入的所有单元格加全边框,默认 true。

类型参数

T
列表元素类型;其公共实例属性按反射顺序作为列。

返回值

Int32
写入的列数,即 max(属性个数, headers?.Length ?? 0),可直接传给 MergeFullRow(Int32, Int32)。

备注

属性通过 GetProperties(BindingFlags) 获取(公共 + 实例), 顺序由反射返回顺序决定,通常与声明顺序一致但不保证,建议显式传入 headers 以固定列顺序。

属性值通过 GetValue(Object) 读取,若属性 getter 抛异常会向上传播。

参见