Solved

Using VB .Net to parse an excel file

Posted on 2004-04-09
2
445 Views
Last Modified: 2010-05-18
Hi

I am current writting a VB .Net app that needs to do the following:

open an existing excel workbook and select a worksheet
search the cells in one column for a string
continue searching the cells in the same column for another string
copy the cells between both strings and push them into a db

I've having difficulty finguring out how to search the cells into order to create the range object, w/o creating the range object to begin wth.

I haven't worked with the Excel object model before so any assistance would be appreciated
0
Comment
Question by:jimmychippewa
2 Comments
 
LVL 28

Accepted Solution

by:
mmarinov earned 500 total points
ID: 10794832
it is not needed to use Excel object - you can work with excel through oledb provider as a database then you can use for example oledbdataadapter.fill(dataset1) and you can going though columns and rows of the tables in filled dataset

B..M
0
 
LVL 9

Expert Comment

by:malharone
ID: 10795025
this code will do ... all you have to do is change sheet name and the function'll return DataSet which you can easily manage


private DataSet TranslatExcelToDataset(string filePath)
{
      string ConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\"{0}\"; Extended Properties=\"Excel 8.0;HDR=No;IMEX=1;\"", filePath);
      OleDbConnection Connection = new OleDbConnection(ConnectionString);
      OleDbDataAdapter Adapter = new OleDbDataAdapter();
      OleDbCommand Command = new OleDbCommand("SELECT * FROM [Sheet1$]", Connection);
      DataSet DS = new DataSet("Table");
      Adapter.SelectCommand = Command;
      Adapter.Fill(DS);
      return DS;
}
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question