MiniExcel icon indicating copy to clipboard operation
MiniExcel copied to clipboard

Improve the method SaveAsByTemplate when using DataTable as parameter directly

Open Rwing opened this issue 4 years ago • 3 comments

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?

Rwing avatar May 24 '21 07:05 Rwing

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
image

shps951023 avatar May 24 '21 09:05 shps951023

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 avatar May 24 '21 09:05 Rwing

@Rwing Would you like to contribute a PR?

tonyqus avatar Apr 02 '25 23:04 tonyqus