MiniExcel
MiniExcel copied to clipboard
DynamicColumn with DataTable not work
Is this by design or bug?
It's not support now
I also think it's not implemented in DataReader? I only want to set the Format with generic columns and I think it is the only way to do it with DynamicColumns
@maui87 yes, they have to implement with unique different logic feature
As for now, we can workaround this by using Dictionary with DynamicColumn.
I solved this by preprocessing my DataTable to the generic list of dictionaries seen in your examples. I recommend deleting the code path GenerateSheetByDataTable and instead converting the different inputs, like DataTable to an object you can feed to a shared GenerateSheet method. This way, it doesn't matter what the input is, the way it is processed should be the same. I have begun looking at your code but I'm not familiar enough with it to issue a PR yet. I hope you understand my suggestion. It's a simple solution.
private static IEnumerable<IDictionary<string, object>> DataTableToListOfDictionary(DataTable dt)
{
foreach (DataRow row in dt.Rows)
{
var rowData = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
var header = col.Caption ?? col.ColumnName );
rowData.Add(header, row(col));
}
yield return rowData;
}
}