473,503 Members | 13,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

best way to read specific record from Excel file in C#

Greetings all,

What is the best way to access specific records in an Excel file?

I have an Excel file, I want to randomly and repeatedly (maybe around up to
50 times) draw some rows of data from this Excel file and store them in a
struct/class for further processing. (mostly just display the info in
graphical format)

This is not some sort of database application, but rather I am
drawing some data for display in a series of experiments. (A
user evaluates how data is displayed)

I am not sure my current approach is the best way to do this, this is
what I do right now:

Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(fileName,0, false, 5,
"", "", false, Excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);

// get the collection of sheets in the workbook
Excel.Sheets sheets = theWorkbook.Worksheets;

// get the first and only worksheet from the collection of worksheets
worksheet = (Excel.Worksheet)sheets.get_Item(1);

(more of this code below)

I would appreciate suggestions/web pointers/sample code on how to do
this best.
Thanks!

Esmail

------------------

what I am doing now:

private Excel.Application ExcelObj = null;
ExcelObj = new Excel.Application();

OpenExcelFile(_fileName);
openedFile = true;
----

private void OpenExcelFile(string fileName)
{
Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(fileName,0,
false, 5,
"", "", false, Excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);

// get the collection of sheets in the workbook
Excel.Sheets sheets = theWorkbook.Worksheets;

// get the first and only worksheet from the collection of worksheets
worksheet = (Excel.Worksheet)sheets.get_Item(1);

max_rec = 1000;

// loop through the rows of the spreadsheet and place each row in the
list view
for (int i = 1; i <= max_rec; i++)
{
Excel.Range range = worksheet.get_Range("A"+i.ToString(), "J" +
i.ToString());
System.Array myvalues = (System.Array)range.Cells.Value2;
string strArray = ConvertToString(myvalues);
listView1.Items.Add(new ListViewItem(strArray));
}
}

---

// to close up the program/excel file

ExcelObj.Quit();
Application.Exit();
Jan 31 '06 #1
1 4608
anyone? somehow i can't believe i'm doing this the best
way already .. so if you have anything to share i'd love
to hear it.

thanks,
esmail
Feb 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1708
by: yvan | last post by:
Approximately once a month, a client of ours sends us a bunch of comma-delimited text files which I have to clean up and then import into their MS SQL database. All last week, I was using a Cold...
1
4116
by: Johnny Meredith | last post by:
Dear All, I have an Access database that tracks the progress of income tax audits. When the taxing authorities make a change (an "Adjustment"), I record the pertinent information in the...
5
1384
by: Ronald S. Cook | last post by:
We have a .NET Win app that runs at 12 different cattle feeding lots. Each lot runs an isolated instance of our app using its own SQL Server instance. For overall settings specific to a feedlot,...
16
10024
by: robertmeyer1 | last post by:
Hey, I am working on creating a query which will export the information to excel. I have a specific excel document which has line by line items (corresponds to access query). Here's the...
1
3378
by: colleen1980 | last post by:
Hi:Can any one please tell me how to convert excel file into a text file thru VB6 Program? Also is it possible that i read the values from the converted text file of any column one by one thru do...
0
2240
by: Vader | last post by:
I am new to this forum. Thanks in advance for and help. The following is what I am looking for: 1. I need help with VB code to open a MS Word (.doc) file. 2. Read lines from the MS Word (.doc)...
3
5694
by: maylee21 | last post by:
hi, anyone can help me figure out how to read data from a text file like this: 10980012907200228082002 and extract the data according to this kind of format: Record type 1 TY-RECORD ...
1
3186
by: prmukkundi | last post by:
hi friends, I am Purushottam, a mechanical engineer.I am trying to write a C++ programme to know the characteristics of control valve(i.e cv,coefficient of valve). Before calculating cv, i need...
3
4199
by: redbenn | last post by:
Hello, I am trying to create an excel macro, that when clicked... a specific cell will match a record in my database, and update certain fields in this record. The Excel file will have a cell...
0
7212
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.