Simple Excel WriterAdd Data Table 方法
从 DataTable 写入。数字列输出为数值单元格,DateTime 列输出 yyyy-MM-dd 文本。
headers 为 null 时用列名作表头;否则按顺序使用传入的表头(不要求与列数一致)。
withBorder 为 true(默认)时所有单元格加全边框。
返回写入的列数,便于调用 MergeFullRow 计算合并列数。
Definition
命名空间: Suresking.Utility
程序集: Suresking.Utility (在 Suresking.Utility.dll 中) 版本:1.3.22+a27276bb8ffde055e69ff608e98aafba279e1e99
写入的列数,即 max(table.Columns.Count, headers?.Length ?? 0),可直接传给 MergeFullRow(Int32, Int32)。
程序集: Suresking.Utility (在 Suresking.Utility.dll 中) 版本:1.3.22+a27276bb8ffde055e69ff608e98aafba279e1e99
C#
public int AddDataTable(
DataTable table,
string[]? headers = null,
bool withBorder = true
)参数
- table DataTable
- 数据源;其 Rows 中每一行写入一行。
- headers String (Optional)
- 自定义表头;为 null 时使用列名,否则按顺序使用(多余的列名忽略,不足的补空字符串)。
- withBorder Boolean (Optional)
- 是否给写入的所有单元格加全边框,默认 true。
返回值
Int32写入的列数,即 max(table.Columns.Count, headers?.Length ?? 0),可直接传给 MergeFullRow(Int32, Int32)。
备注
先写一行表头,再逐行写数据。列数取表头长度与 DataTable 列数的较大者,
因此当表头比数据列多或少时也不会错位,多出的单元格为空字符串。