Solved

vb.net import excel file

Posted on 2007-04-02
7
15,773 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

739 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