Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88066

Exporting list of strings to an excel cell using EPPlus

$
0
0

I'm currently trying to export some DataTable data to excel. One of the columns in my table is 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
    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. What am I doing wrong here, and how can I have this List column correctly exported to excel?


Viewing all articles
Browse latest Browse all 88066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>