Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
Reading an Excel File
posted

I am trying to read a value from a specifi cell and all I am getting is a 'nothing' for the value.

I can see the worksheet name on the cells with the correct index, but I do not have a value for the cell.

What am I doing wrong?

I am using VB .Net 2005 with NetAdvantage 7.2

My code is as follows

Dim oWorkbook As Workbook

Dim oWorkSheet As Worksheet

Dim iMaxRecord As Int64

Dim iLoop As Int64

Dim strRefNumber As String

Dim strCollectionStatus As String

Dim dAmountCollected As Double

Dim dtCollectionDate As Date

Dim iCentreId As Int16

Dim iCustomerId As Int64

Dim iContractid As Int64

 

Try

oWorkbook = Workbook.Load(strFilename)

For Each oWorkSheet In oWorkbook.Worksheets

iMaxRecord = 0

Do While Not oWorkSheet.Rows(iMaxRecord).Cells(8).Value Like "Totals*"

iMaxRecord += 1

Loop

For iLoop = 1 To iMaxRecord

If IsNumeric(oWorkSheet.Rows(iLoop).Cells(1).Value) Then

strRefNumber = oWorkSheet.Rows(iLoop).Cells(2).Value

strCollectionStatus = oWorkSheet.Rows(iLoop).Cells(6).Value

dAmountCollected = oWorkSheet.Rows(iLoop).Cells(11).Value

dtCollectionDate = oWorkSheet.Rows(iLoop).Cells(8).Value

iCentreId = Mid(strRefNumber, 1, 2)

If InStr(strRefNumber, "/") = 0 Then

iCustomerId = Mid(strRefNumber, 3, Len(strRefNumber) - 2)

iContractid = 0

Else

iCustomerId = Mid(strRefNumber, 3, InStr(strRefNumber, "/") - 3)

iContractid = Mid(strRefNumber, InStr(strRefNumber, "/") + 1)

End If

UpdateCollectionStatus(iCentreId, iCustomerId, iContractid, strCollectionStatus, dtCollectionDate, dAmountCollected)

End If

Next

Next

Catch ex As Exception

MessageBox.Show(ex.Message)

Finally

oWorkSheet = Nothing

oWorkbook = Nothing

End Try