473,598 Members | 3,369 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.Workbo oks.Open(fileNa me,0, false, 5,
"", "", false, Excel.XlPlatfor m.xlWindows, "",
true, false, 0, true, false, false);

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

// get the first and only worksheet from the collection of worksheets
worksheet = (Excel.Workshee t)sheets.get_It em(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.Applicati on ExcelObj = null;
ExcelObj = new Excel.Applicati on();

OpenExcelFile(_ fileName);
openedFile = true;
----

private void OpenExcelFile(s tring fileName)
{
Excel.Workbook theWorkbook = ExcelObj.Workbo oks.Open(fileNa me,0,
false, 5,
"", "", false, Excel.XlPlatfor m.xlWindows, "",
true, false, 0, true, false, false);

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

// get the first and only worksheet from the collection of worksheets
worksheet = (Excel.Workshee t)sheets.get_It em(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_R ange("A"+i.ToSt ring(), "J" +
i.ToString());
System.Array myvalues = (System.Array)r ange.Cells.Valu e2;
string strArray = ConvertToString (myvalues);
listView1.Items .Add(new ListViewItem(st rArray));
}
}

---

// to close up the program/excel file

ExcelObj.Quit() ;
Application.Exi t();
Jan 31 '06 #1
1 4618
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
1720
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 Fusion script to upload the cleaned up files and then import the records they contained into the database, though obviously, the process took friggin' forever, and could have been done 500x quicker had I done it directly on the server. My SQL...
1
4119
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 database. At the end of the audit cycle, these adjustments are used to compute the revised taxes due. This computation is done in a fairly complex, but accurate and easy to use, spreadsheet. In the spreadsheet, there is a sheet that lists out all...
5
1390
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, we're maintaining those values right now in the database. But I'm not sure its the best way to do it. You see, we have a table "tblFeedlot" with about 20 columns BUT then only one record in the table. I thought maybe the table should have...
16
10047
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 layout of the excel doc. Each row is a different line item. Each column is a different entity. So there are about 750 entities which will be exported to this excel doc. (1 entity per column). For access, I have the same information as the excel...
1
3388
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 while loop? Or can i read the values of any column directly from excel file without converting into a textfile thru do while loop? Thanks, Anna.
0
2245
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) file 3. Save the specific/parsed data on one of the sheets in MS Excel spread sheet. 4. Close up the MS Word (.doc) file. The VB part is based on the MS Excel spreadsheet file . One of the sheet on spreedsheet will have the path name and file...
3
5703
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 PIC (1). ID-PARTICIPANT PIC (6).
1
3194
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 to know the density,which is a property of the fluid & that depends on pressure & temperature.So, i mean to say, it has to be read from steam tables.But, till now, we are doing the same thing using simple excel calculation & density & all other...
3
4212
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 that is the same as a 'Tracking Number' (the primary key) of my Access Table. The output from excel would access this record and update the field. I currently have a macro to create new records in the table, but I am not sure if there is a way to...
0
7991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7902
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8265
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6719
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5438
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2412
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 we have to send another system
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.