thebatfink
Well-known member
- Joined
- Mar 29, 2012
- Messages
- 47
- Programming Experience
- Beginner
Hi,
I have a small program which is opening and scraping Excel work books and loading the data into a local SqlCe database.
One of the cells I am trying to scrape is causing me no end of problems and I don't understand why it's the case. It doesn't make any sense to me.
The cell.value can contain any of the following types of data:
- Integer
- Decimal
- String (specifically 'ERR')
What I need to do is convert whatever is there, into an integer. I have been doing this by using conditional arguements to test the contents, if its a string, my integer is 0. If its not a string, I perform an integer.tryparse and then finally set the integer to 0.. but for some reason the following fails..
Now if I use the following to test for the cell containing the string "ERR", I get an error saying
'Conversion from string "ERR" to type "Double" is not valid'
But if I use the following to test, it works ok and captures the presence of the string?
So I have found a working solution to my problem, but I would really appreciate if someone could give me an understanding as to why the first test is trying to convert the cell contents to type double before making the comparison!
Thanks!
I have a small program which is opening and scraping Excel work books and loading the data into a local SqlCe database.
One of the cells I am trying to scrape is causing me no end of problems and I don't understand why it's the case. It doesn't make any sense to me.
The cell.value can contain any of the following types of data:
- Integer
- Decimal
- String (specifically 'ERR')
What I need to do is convert whatever is there, into an integer. I have been doing this by using conditional arguements to test the contents, if its a string, my integer is 0. If its not a string, I perform an integer.tryparse and then finally set the integer to 0.. but for some reason the following fails..
VB.NET:
Dim PlanWorkBook As Excel.Workbook
Dim PlanWorksheet As Excel.Worksheet
....
PlanFileName = HMFileList(i)
PlanWorkBook = ExcelApp.Workbooks.Open(PlanFileName, [ReadOnly]:=True, UpdateLinks:=False)
For Each Sheet As Excel.Worksheet In PlanWorkBook.Worksheets
If Sheet.CodeName = "Sheet2" Then
WorkSheetindex = Sheet.Index
End If
Next
PlanWorksheet = PlanWorkBook.Sheets(WorkSheetIndex)
'Conversion from string "ERR" to type "Double" is not valid'
VB.NET:
If PlanWorksheet.Range("A" & j & "").Value = "ERR" Then
VB.NET:
If Right(PlanWorksheet.Range("A" & j & "").Value, 3) = "ERR" Then
Thanks!