0

I have few Excel files that contain three columns of data(numbers only) that I would like to store as C# objects. These objects will then be used to populate a Report chart in Visual Studio. Is there an easy way to convert this data to objects in C#? So, I would like to import this data into a list or collection in C#. Then use this list to create a chart.

I have looked around and there seem to be external libraries that read/write to Excel files but I am not in favor of external libraries. Also, I would like to point out that I am not using mysql. I am creating objects in memory and populating my report in Visual Studio with these objects.

Thank you!

Shruti Kapoor
  • 1,106
  • 2
  • 12
  • 32
  • Apparently there's a LINQ to Excel provider - http://msdn.microsoft.com/en-us/library/office/dd920313(v=office.12).aspx – evanmcdonnal May 24 '13 at 16:39
  • 1
    If the Excel files don't have to remain Excel files, you convert them to CSV. Otherwise, Visual Studio Tools for Office may be of assistance. – mason May 24 '13 at 17:02

3 Answers3

1

The method here works for me :

https://stackoverflow.com/a/37164563/4573839

Use it and you can turn Excel into DataTable, Then just use the General Way to turn the Rows and Columns of DataTable into Object's Property,

For exapmle suppose dr is one of the DataRow, you can get data by dr["ColumnName"], and the ColumnName possibly is the upmost cell of the column in Excel Sheet.

Community
  • 1
  • 1
yu yang Jian
  • 6,680
  • 7
  • 55
  • 80
0

I would recommend Open XML SDK for reading Excel Files and converting the data into .NET objects.

cvraman
  • 1,687
  • 1
  • 12
  • 18
0

You can use SQL queries in your Excel files and use the results to populate your object (or your reports directly), for more info take a look here: How to query excel file in C# using a detailed query

Community
  • 1
  • 1
Rafael
  • 2,827
  • 1
  • 16
  • 17