Reading an Excel sheet by cell in c#

Jun 2, 2008
163
0
0
I've been looking online and I still am stuck.

I'd like to select certain cells out of 50+ excel files.

Each file is the same, just different numbers.

So say I want to extract

A1, B5, C7, D9 etc..... What is my best approach?

I found some c# code and I'm able to capture one cell but I have to do a Define Name on the cell in Excel which I can't do because I'd have to edit 50+ files.

So say I want to capture A1. In excel I go to Define Name, give it a name.

http://www.geekpedia.com/tutor...adsheet-using-ASP.html

Then in c# I can make a query like this.

SELECT * FROM Projnum <---- Projnum is the defined name. The link above explains.

Is it possible to do something like

SELECT * FROM Sheet1$A1 or something???

I need to read 50+ cells and there is no order to them, they are are individual and then send it to a csv file.
 

techfuzz

Diamond Member
Feb 11, 2001
3,107
0
76
Excel.Range objRange = (Excel.Range)objSheet.Cells[1,1];
strData = objRange.get_Value(Missing.Value).ToString();

techfuzz
 
Jun 2, 2008
163
0
0
Dhaval00, it's a form so there's a lot of useless things that I would pick up.

Thanks, techfuzz, I got that to work.

I have one issue...

I can't use Excel.Range...

What I can use is Microsoft.Office.Interop.Excel.Range.

I registered it at the top as using Microsoft.Office.Interop.Excel; but it still doesn't work. Would you have any ideas?
 

Snapster

Diamond Member
Oct 14, 2001
3,916
0
0
To use office automation you'll need office installed first then you need to add a reference to Microsoft.Office.Interop.Excel. If it's just a simple data structure then save it as csv and read the text file in and split it using the delimiters, much simpler.