Link to home
Start Free TrialLog in
Avatar of jimmychippewa
jimmychippewa

asked on

Using VB .Net to parse an excel file

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
ASKER CERTIFIED SOLUTION
Avatar of mmarinov
mmarinov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of malharone
malharone

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;
}