We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to read rows into a List<T>

I’m evaluating the Aspose.Cells trial, my use case is to read and process the data in Excel worksheets using C#.

In EPPlus I can do: var rows = worksheet.Extract() … to create a List of custom objects, I have only found ExportDataTable which isn’t friendly for this,
can anyone point me in the right direction, docs, code samples

Regards

@PrisonerZero,

Thanks for your query.

You may please have a look at the following link and provide your feedback.
Columns Containing Non-Strongly Typed Data

If it does not fulfill your requirements, share your sample file containing sample data for our testing. We will reproduce the scenario and provide our feedback after analysis.

Thanks I see how to do it now, here’s my solution:

image.png (3.6 KB)

        DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0, 3, 4, true);
        List<Sale> sales = dataTable.Rows.OfType<DataRow>().ToList().Select(dr => new Sale
        {
            Salesman = dr.Field<string>("Salesman"),
            Item = dr.Field<string>("Item"),
            Value = dr.Field<double>("Value"),
            Date = dr.Field<DateTime>("Date")
        }).ToList();

class Sale
{
public string Salesman { get; set; }
public string Item { get; set; }
public double Value { get; set; }
public DateTime Date { get; set; }
}

@PrisonerZero,

Good to know that your issue is sorted out by the suggested line of code. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.