MiniExcel
MiniExcel copied to clipboard
Improve the method SaveAsByTemplate when using DataTable as parameter directly
scenario:
var dataTable = AdoNet.ExecuteDataTable("SELECT * FROM Table");
MiniExcel.SaveAsByTemplate(resultFilePath, templateFilePath, dataTable);
I knew wrapping it to an object would solve the problem, but wouldn't that be easier to use?
Do you want below logic?
Template
| Name | Age |
|---|---|
| {{Name}} | {{Age}} |
Code
var datatable = new DataTable();
datatable.Columns.Add("Name");
datatable.Columns.Add("Age");
datatable.Rows.Add("Jack",18);
datatable.Rows.Add("Henry",27);
MiniExcel.SaveAsByTemplate(path,templatePath,datatable);
Result
| Name | Age |
|---|---|
| Jack | 18 |
| Henry | 27 |
Why not simplify like it? Because miniexcel have to consider the mixed use of IEnumerable and non-IEnumerable
e.g

yea, I know what you mean. but I don't think it's a conflict if add another DataTable logic. maybe the code will become ugly?
@Rwing Would you like to contribute a PR?