Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Reading Excel 2007 Rows in C# / .Net

I am trying to read an Excel spreadsheet row by row and transform the data in
each row into my own business object. I am trying to figure out the "best
practice" for doing this in C# / .NET 3.5 (VS2008). I have tried the
following:

1. Using an OleDbConnection to "SELECT FROM" my particular worksheet into a
DataTable. Then I must iterate over the DataTable and pull the data I want
from each DataRow. Actually this seems to be the most straightforward from a
coding perspective.

2. I found this example to read a particular cell from a worksheet using an
XmlDocument: http://msdn.microsoft.com/en-us/library/bb332058.aspx. This
seems to have A LOT of code behind it just to read one cell. And I am unsure
how to modify this code to iterate over the worksheet one row at a time.

3. Using Interop. I had an example using Interop to open the document and
read a worksheet. Then I found I had to read a range on a per column basis
into an array, and then I had to transform the data in the array into what I
was looking for. This also seems very cumbersome. Also, I had a working
example for an Excel 2003 spreadsheet, but when I tried to use the same code
to open an Excel 2007 spreadsheet, I got an "out of memory" error when just
opening the file. I'm not sure if I have some parameter not set correctly in
this case.

I am not sure if this is the correct forum to ask this question as this may
be more for the mechanics of using Excel rather than trying to read the file
programmatically. It seemed that using the OleDbConnection was not the
preferred method any more, but it seems to be the most straightforward for my
needs. Just wondering if anyone had any thoughts on this.

Thanks,
Beth
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Reading Excel 2007 Rows in C# / .Net

On Mon, 9 Mar 2009 16:39:01 -0700, BethH
wrote:

I am trying to read an Excel spreadsheet row by row and transform the data in
each row into my own business object. I am trying to figure out the "best
practice" for doing this in C# / .NET 3.5 (VS2008). I have tried the
following:

1. Using an OleDbConnection to "SELECT FROM" my particular worksheet into a
DataTable. Then I must iterate over the DataTable and pull the data I want
from each DataRow. Actually this seems to be the most straightforward from a
coding perspective.

2. I found this example to read a particular cell from a worksheet using an
XmlDocument: http://msdn.microsoft.com/en-us/library/bb332058.aspx. This
seems to have A LOT of code behind it just to read one cell. And I am unsure
how to modify this code to iterate over the worksheet one row at a time.

3. Using Interop. I had an example using Interop to open the document and
read a worksheet. Then I found I had to read a range on a per column basis
into an array, and then I had to transform the data in the array into what I
was looking for. This also seems very cumbersome. Also, I had a working
example for an Excel 2003 spreadsheet, but when I tried to use the same code
to open an Excel 2007 spreadsheet, I got an "out of memory" error when just
opening the file. I'm not sure if I have some parameter not set correctly in
this case.

I am not sure if this is the correct forum to ask this question as this may
be more for the mechanics of using Excel rather than trying to read the file
programmatically. It seemed that using the OleDbConnection was not the
preferred method any more, but it seems to be the most straightforward for my
needs. Just wondering if anyone had any thoughts on this.

Thanks,
Beth


Not every expert using Excel is also an expert using C# / .NET
I suggest you ask your question in a C# / .NET forum.
--
Chuck
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading and writing to ini files in Excel 2007 Rolf Gustafsson Excel Programming 3 January 18th 09 08:38 PM
EXCEL 2007 reading E as power of ten DoubleZ Excel Discussion (Misc queries) 2 August 1st 08 05:30 PM
Excel: reading tables with multiple rows and columns R.A. Clarke Excel Programming 1 July 16th 08 01:22 PM
IE automation, Frames content reading problem, excel 2003 and 2007 Piotr Zaniewski Excel Programming 0 August 29th 07 02:37 PM
Stop Excel reading 01/02 as 1st February 2007 Jon Stenning Excel Discussion (Misc queries) 5 July 30th 07 04:58 PM


All times are GMT +1. The time now is 08:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"