Solved

Using VB .Net to parse an excel file

Posted on 2004-04-09
2
443 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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now