首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

vb.net怎么访问excel表格?报错:range向string转换出错。着急

2012-02-26 
vb.net如何访问excel表格?报错:range向string转换出错。着急啊!!!代码如下:WithxlSheetFori13To453If.Cell

vb.net如何访问excel表格?报错:range向string转换出错。着急啊!!!
代码如下:
With   xlSheet
                        For   i   =   13   To   453

                                If   .Cells(i,   1)   Is   System.DBNull.Value   Then
                                        no   =   " "
                                Else
                                        no   =   CType(.Cells(i,   1),   String)
                                End   If

                                If   .Cells(i,   2)   Is   System.DBNull.Value   Then
                                        name   =   " "
                                Else
                                        name   =   CType(.Cells(i,   2),   String)
                                End   If

                                If   .Cells(i,   3)   Is   System.DBNull.Value   Then
                                        unit   =   " "
                                Else
                                        unit   =   CType(.Cells(i,   3),   String)
                                End   If

                                If   .Cells(i,   7)   Is   System.DBNull.Value   Then
                                        remark   =   " "
                                Else
                                        remark   =   CType(.Cells(i,   7),   String)
                                End   If


                                cmm.CommandText   =   "insert   into   fixproject(number,fname,unit,remark)   values( ' "   &   no   &   " ', ' "   &   name   &   " ', ' "   &   unit   &   " ', ' "   &   remark   &   " ') "


                                cmm.ExecuteNonQuery()
                        Next

                End   With

出错提示如下:
从类型“Range”到类型“String”的强制转换无效。  
说明:   执行当前   Web   请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。  

异常详细信息:   System.InvalidCastException:   从类型“Range”到类型“String”的强制转换无效。

[解决办法]
Cells(i, 7).Value

Cells(i, 7)这从集合里取出来是CELL

热点排行