Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Exporting DataTable with columns whose type is a collection #595

Open
mdmilic opened this issue Dec 17, 2019 · 0 comments
Open

Exporting DataTable with columns whose type is a collection #595

mdmilic opened this issue Dec 17, 2019 · 0 comments

Comments

@mdmilic
Copy link

mdmilic commented Dec 17, 2019

I'm currently trying to export some DataTable data to excel. One of the columns in my table is of type List<string>. I first create a DataTableReader and then try to load the data into a worksheet using LoadFromDataReader like so:

public static ToReader(List<object> data)
{
    var toReturn = new DataTable();
    // Complex code about creating the data table
    return new DataTableReader(toReturn);
}
//...
public static Export(List<object> data)
{
    using (var pck = new ExcelPackage())
    {
        // add the content into the Excel file
        ExcelWorksheet ws = pck.Workbook.Worksheets["Data"];
        ws.Cells[startCell].LoadFromDataReader(ToReader(data), true);
        //....
    }
}

All the data gets exported to excel just fine except for the column which contains List<string>. For this column I would expect the cell value to be comma separated values of that list, instead I just get the first element of the list.

E.g. if the list was {"Fee", "Fi", "Fo", "Fum"}, I would expect the cell value to be "Fee, Fi, Fo, Fum", instead I get "Fee".

From debugging I see that data is correctly written to the DataTableReader, so the problem must be with loading it into excel.

From SO answers it seems that the culprit is this part of EPPlus code.

Is this an issue with EPPlus or for some reason this is desired behavior?
I couldn't find the issue mentioned in the EPPlus code.

@mdmilic mdmilic changed the title columns with collection Exporting DataTable with columns whose type is a collection Dec 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant