In this article I will show how to read value from excel per cell,

First Im using FileUpload component from asp.net

	<td>
                <asp:FileUpload ID="uplFile" runat="server"  Width="367px"/>
	</td>


Don’t Forget to add triger to set autopostback, or else some people may counter error when the want to get the file name after they click browse button. Normally you put this code at the buttom

      	<triggers>
              <asp:PostBackTrigger ControlID="btnUpload" />
        </triggers>

At behind code import
Imports Excel = Microsoft.Office.Interop

In event click

        Dim oApp As New Excel.Excel.Application()
        Dim oWBa As Excel.Excel.Workbook
        Dim oWS As Excel.Excel.Worksheet

            If uplFile.PostedFile.FileName <> "" Then
                filename = Mid(uplFile.PostedFile.FileName, InStrRev(uplFile.PostedFile.FileName, "\") + 1, Len(uplFile.PostedFile.FileName) - InStrRev(uplFile.PostedFile.FileName, "\"))
                uplFile.PostedFile.SaveAs(System.AppDomain.CurrentDomain.BaseDirectory & filename)

                oWBa = oApp.Workbooks.Open(System.AppDomain.CurrentDomain.BaseDirectory & filename)
                oWS = DirectCast(oWBa.Worksheets(1), Excel.Excel.Worksheet)
                oApp.Visible = False

                    Dim strkey2(3) As String
                    strkey2(0) = CStr(oWS.Range("A1")
                    strkey2(1) = CStr(oWS.Range("B1")
                    strkey2(2) = CStr(oWS.Range("C1")
                    strkey2(3) = CStr(oWS.Range("D1")

                   oWS = Nothing
                   oWBa.Close()
                   oWBa = Nothing
                   oApp.Quit()
                   oApp = Nothing

     End If

  • Share/Bookmark