Foxtable(狐表)用户栏目专家坐堂 → 关于导入excel的代码(已解决)


  共有9588人关注过本帖平板打印复制链接

主题:关于导入excel的代码(已解决)

帅哥哟,离线,有人找我吗?
yyzlxc
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1525 积分:10580 威望:0 精华:0 注册:2008/9/24 11:16:00
关于导入excel的代码(已解决)  发帖心情 Post By:2012/11/7 15:53:00 [只看该作者]

一段导入excel的代码,能够解决excel表的单元格为空时,导入出错的问题。现要求只导入“项目”列,值为“本月数”行的值,应该如何修改代码,请各位老师指教,谢谢!!

        For r As Integer = 1 To Sheet.Rows.Count - 1
            Dim Filter1 As String = ""
            For c As Integer = 0 To Sheet.Cols.Count - 1
                If c > 0 Then
                    Filter1 = Filter1 & " And "
                End If
                If sheet(r,c).Value <> "" AndAlso CurrentTable.DataTable.DataCols(sheet(0,c).Value).IsNumeric Then
                    Filter1 = Filter1 & sheet(0,c).Value & " = " & sheet(r,c).Value
                ElseIf sheet(r,c).Value = "" Then
                    Filter1 = Filter1 & sheet(0,c).Value & " is null "
                Else
                    Filter1 = Filter1 & sheet(0,c).Value & " = '" & sheet(r,c).Value & "'"
                End If
            Next
            If CurrentTable.DataTable.Find(Filter1) Is Nothing Then
                Dim dr As Row = CurrentTable.AddNew()
                For c As Integer = 0 To Sheet.Cols.Count - 1
                    dr(Sheet(0,c).Value) = Sheet(r,c).Value
                Next
            End If
        Next
[此贴子已经被作者于2012-11-8 9:15:29编辑过]

 回到顶部