Hi, I am making a parsing program that needs to get the data from an excel document (xlsx file) and pass it into a SQL database. I am having some issues trying to figure out how to read the data from only specific columns (I don't need some of the data
from the sheet). The file is being uploaded and read from a stream so I need to use OpenXML. Is there a way to select/ignore a column with OpenXML SDK 2.0? Please keep in mind I am pretty new to MVC and OpenXML.
I managed to figure it out. In my case I just made a variable to store the CellReference for each cell and then made a StartsWith comparison for the column name (i.e. B). I didn't think of anything that simple (and I didn't know of the StartsWith method
before starting this).
Hi, you may be interested in the following screen-cast and code that shows a convenient way to query a spreadsheet. It is pretty easy to retrieve just the values for a specific column. The code presented in the screen-cast is written in VB.NET, but the
actual 'library' is written in C#.
Tolsen
0 Points
2 Posts
How to read specific columns with Openxml.
Dec 03, 2012 03:56 PM|LINK
Hi, I am making a parsing program that needs to get the data from an excel document (xlsx file) and pass it into a SQL database. I am having some issues trying to figure out how to read the data from only specific columns (I don't need some of the data from the sheet). The file is being uploaded and read from a stream so I need to use OpenXML. Is there a way to select/ignore a column with OpenXML SDK 2.0? Please keep in mind I am pretty new to MVC and OpenXML.
Tolsen
0 Points
2 Posts
Re: How to read specific columns with Openxml.
Dec 03, 2012 08:09 PM|LINK
I managed to figure it out. In my case I just made a variable to store the CellReference for each cell and then made a StartsWith comparison for the column name (i.e. B). I didn't think of anything that simple (and I didn't know of the StartsWith method before starting this).
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to read specific columns with Openxml.
Dec 04, 2012 03:40 AM|LINK
Hi,
Congratulation!
I'll close your issue and if you have feedback things, please create another new one.
Reguards!
EricWhiteDev
Member
8 Points
4 Posts
Re: How to read specific columns with Openxml.
Dec 05, 2012 02:21 AM|LINK
Hi, you may be interested in the following screen-cast and code that shows a convenient way to query a spreadsheet. It is pretty easy to retrieve just the values for a specific column. The code presented in the screen-cast is written in VB.NET, but the actual 'library' is written in C#.
http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2011/07/18/query-open-xml-spreadsheets-in-vb-net-using-linq.aspx
You can find C# code to use the small 'library' at the following URL:
http://blogs.msdn.com/b/ericwhite/archive/2008/11/14/using-linq-to-query-excel-tables.aspx
-Eric