how to upload excel file in vb.net?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nandhini Mani
    New Member
    • Nov 2011
    • 1

    how to upload excel file in vb.net?

    hi,
    Anybody help me?I have error "Arithmetic operation resulted in overflow"and how to rectify this.
    Try

    Dim objOFD As New OpenFileDialog

    'Set the Open dialog properties
    With objOFD
    .Filter = "Excel files (*.xlsx)|*.xlsx |Excel files (*.xls)|*.xls"
    .FilterIndex = 1
    .Title = "Select excel file to upload"
    End With
    If (objOFD.ShowDia log = Windows.Forms.D ialogResult.OK) Then
    If (MsgBox("Are you sure want to upload this excel file?", MsgBoxStyle.Yes No, "Excel file uploading") = MsgBoxResult.Ye s) Then

    Dim xlApp As Excel.Applicati on
    Dim xlWorkBook As Excel.Workbook
    Dim xlWorkSheet As Excel.Worksheet
    Dim range As Excel.Range
    Dim rCnt As Integer
    Dim cCnt As Integer
    Dim Obj As Object


    ' customername = "Newcustome r"

    xlApp = New Excel.Applicati onClass
    xlWorkBook = xlApp.Workbooks .Open(objOFD.Fi leName.ToString )
    xlWorkSheet = xlWorkBook.Work sheets("sheet1" )

    range = xlWorkSheet.Use dRange

    ' For rCnt = 2 To range.Rows.Coun t
    For rCnt = 2 To 2
    For cCnt = 1 To range.Columns.C ount
    Obj = CType(range.Cel ls(rCnt, cCnt), Excel.Range)
    ' MsgBox(Obj.valu e)
    If rCnt = 2 And cCnt = 1 Then
    If (Obj.value <> Nothing) Then ContractorName = Obj.value.ToStr ing.Trim Else ContractorName = ""
    ElseIf rCnt = 2 And cCnt = 2 Then
    If (Obj.value <> Nothing) Then ContractorConta ctno = Obj.value.ToStr ing.Trim Else ContractorConta ctno = ""
    End If

    Next
    Next
    insertContracto rName()

    MsgBox(Contract orName & " Successfully Updated!", MsgBoxStyle.Inf ormation)
    Else
    MsgBox(Contract orContactno & " already exists!", MsgBoxStyle.Cri tical)
    End If

    objOFD.Dispose( )
    objOFD = Nothing

    End If

    Catch ex As Exception
    MsgBox(ex.Messa ge)
    End Try
Working...