Solved

vb.net import excel file

Posted on 2007-04-02
7
15,757 Views
Last Modified: 2013-12-16
I have a file browser that will select an excel file.  How do I import it into the application?  Do I open and read each line, one at at time?  Can someone post some code?

Thanks
0
Comment
Question by:jackjohnson44
  • 4
  • 2
7 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 18839958
What version of Visual Studio are you using?

What do you want to do with the Excel file once you've imported it?
0
 
LVL 21

Accepted Solution

by:
theGhost_k8 earned 500 total points
ID: 18841598
please reply to Chaosian !!

there are may solutions on EE it self:
you are not making urself clear enough.
here are few:

0) <link : http://www.experts-exchange.com/Programming/Misc/Q_21879423.html?sfQueryTermInfo=1+excel+file+net+read#a16864368>

Function ReadDataFromExcel(ByVal excelfilename As String) As DataSet
        Dim ds As New DataSet
        Dim da As OleDbDataAdapter
        Dim conn As OleDbConnection
        Try

            conn = New OleDbConnection( _
                  "provider=Microsoft.Jet.OLEDB.4.0; " & _
                  "data source=" & excelfilename & "; " & _
                  "Extended Properties=Excel 8.0;")

            da = New OleDbDataAdapter("SELECT * FROM [Sheet1$]", conn)

            conn.Open()

            da.Fill(ds)


        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            If conn.State = ConnectionState.Open Then
                conn.Close()
            End If
        End Try
      ReadDataFromExcel=ds
    End Function

1) from prakash

please avoid Excel.Application in ASP.NET Application .
Because Excel.Application need a parent window handle on save a dialog.

It also decreases the performance of the web server

If u using Excel.Application u must have Office Installed on the Web Server.
U do not need Office for Oledb Driver...

for oledb try this sample link...
http://www.codeproject.com/csharp/Excel_using_OLEDB.asp

If u want to do richer functionality try aspose following Component..
http://www.aspose.com/
 

2)




http://blog.lab49.com/?p=196
0
 

Author Comment

by:jackjohnson44
ID: 18843292
I am making a vb.net windows application.  I will open it loop through each line put it in a dataset if it passes my validation, put it in another if it does not and either save the problems in another excel file, or the same one with a different name.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:jackjohnson44
ID: 18843320
it looks like that code will only work with excel 8.0.
Is there an easier way to do this?

Thanks
0
 

Author Comment

by:jackjohnson44
ID: 18843333
sorry, typo, I meant more generic so I don't have to speficy version.  I really don't know what kind they will use.
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 18843385
What version of Visual Studio are you using?
0
 

Author Comment

by:jackjohnson44
ID: 18844664
sorry, vs2005.

I got the code above to work.  I can see the dataset in the dataset viewer with the column names being the top row of the excel file.  unfortunately, I can't seem to access the rows by name, which I need to do if I want to validate.

In the example below, I can see "FirstName" in the  viewer, I can access it by index, but I can't access it by name as seen below.

Any ideas?

        For Each dr As DataRow In dsImport.Tables(0).Rows
            If Len(dr("FirstName")) Then
                fail = True
            End If
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

803 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