sql - Searching Excel Document Columns with Visual Basic and Interop -


i'm struggling problem involves interop , excel. basically, have excel files columns contain "headers" , rows beneath columns have data. example, column age have 12,14,etc underneath it. new interop , i'm trying allow user enter name of column header wish extract data from, if enter "age", it'll find age colum b example , extract data proceeding rows.

i've googled extensively , haven't found solid, rather context orientated , being new interop makes little tricky.

what i've got far:

public sub getexceldata(byval directory string)     dim excelappfirstfile excel.application = nothing     excelappfirstfile = createobject("excel.application")     try         excelappfirstfile.workbooks.open(directory)         dim excelsheet excel.worksheet = excelappfirstfile.worksheets(1)     catch ex exception         msgbox("there problem: " + ex.message)     end try   end sub 

i know isn't i've gone in circles ranges,etc , can't figure out how need to. edit: forgot add column name being searched variable called field set @ earlier stage user.

if want read data in excel file, suggest use oledb instead of interop (which faster):

dim filepath string = "c:\book1.xls" dim connectionstring string = (convert.tostring("provider=microsoft.jet.oledb.4.0;data source=") & filepath) + ";extended properties=""excel 8.0"";" dim connection new oledbconnection(connectionstring) dim cmdtext string = "select * [sheet1$]" dim command new oledbcommand(cmdtext, connection)  command.connection.open() dim reader oledbdatareader = command.executereader()  if reader.hasrows     while reader.read()         console.writeline("{0}" & vbtab & "{1}", reader(0).tostring(), reader(1).tostring())     end while end if 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -