Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving a list of dictionary items creates empty XL file #191

Open
mkgn opened this issue May 12, 2022 · 1 comment
Open

Saving a list of dictionary items creates empty XL file #191

mkgn opened this issue May 12, 2022 · 1 comment

Comments

@mkgn
Copy link

mkgn commented May 12, 2022

I am using XL Mapper version 5.2.352 with .Net core 5.

Since my data structure can contain varying number of columns I have those data arranged in a collection of dictionaries. A dictionary has data similar to below;

image

I assume the Keys of the dictionary will be taken as column headings and the values of each dictionary will be written as rows in the XL.

var mylist = new List<IDictionary<string, string>>();
//fill data to a new dictionary instance
var itemdict = new Dictionary.....
mylist.Add(itemdict);

....
xlMapper.Save(fileName, mylist); 

When I do this as above it throws below exception;

System.Reflection.TargetParameterCountException
Parameter count mismatch.

System.Reflection.TargetParameterCountException: Parameter count mismatch.
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at Ganss.Excel.ColumnInfo.GetProperty(Object o)
at Ganss.Excel.ExcelMapper.SetCell[T](Func3 valueConverter, T objInstance, ICell cell, ColumnInfo ci) at Ganss.Excel.ExcelMapper.SetCells(TypeMapper typeMapper, Dictionary2 columnsByIndex, Object o, IRow row, Func3 valueConverter) at Ganss.Excel.ExcelMapper.Save[T](Stream stream, ISheet sheet, IEnumerable1 objects, Func3 valueConverter) at Ganss.Excel.ExcelMapper.Save[T](Stream stream, IEnumerable1 objects, Int32 sheetIndex, Boolean xlsx, Func3 valueConverter) at Ganss.Excel.ExcelMapper.Save[T](String file, IEnumerable1 objects, Int32 sheetIndex, Boolean xlsx, Func`3 valueConverter)

However if I change my code to;

var mylist = new List<dynamic>(); //earlier it was of type IDictionary<string, string>
//fill data to a new dictionary instance
var itemdict = new Dictionary.....
mylist.Add(itemdict);

....
xlMapper.Save(fileName, mylist); 

Now it doesn't throw an exception, but nothing gets written to the file.

How can I get this done properly?

@mganss
Copy link
Owner

mganss commented May 13, 2022

This use case isn't currently supported. The closest is support for dynamic objects so you could pass a list of ExpandoObject (which implements IDictionary<string, object>) to Save(). Still this necessitates that each object in the list has all keys, possibly with null values for the unused columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants