Foxtable(狐表)用户栏目专家坐堂 → 合并电子表格数据疑问?


  共有9893人关注过本帖树形打印复制链接

主题:合并电子表格数据疑问?

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


加好友 发短信
等级:小狐 帖子:376 积分:4189 威望:0 精华:0 注册:2008/9/1 14:18:00
合并电子表格数据疑问?  发帖心情 Post By:2012/10/12 20:49:00 [只看该作者]

 

Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog

dlg.Filter= "Excel文件|*.xls" '设置筛选器

If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮

    Dim Book As New XLS.Book(dlg.FileName)

    Dim Sheet As XLS.Sheet = Book.Sheets(0)

    For i As Integer = 0 To Sheet.Cols.Count -1

        If CurrentTable.Cols.Contains( Sheet(0,i).Value) = False Then

            MessageBox.Show("目标文件不含【" & Sheet(0,i).Value & "】列,请修改与目标文件一致!", "导入错误提示")

            Return

        End If

    Next

   

    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 IsNumeric(sheet(r,c).Value) Then

                Filter1 = Filter1 & sheet(0,c).Value & " = " & sheet(r,c).Value

            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

End If

 

 

上述代码为能正确执行合并电子表格数据

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目4.foxdb

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:sj.xls


 回到顶部
帅哥哟,离线,有人找我吗?
布莱克朱
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:623 积分:3897 威望:0 精华:0 注册:2011/8/3 22:13:00
  发帖心情 Post By:2012/10/12 21:15:00 [只看该作者]

你这个为什么要筛选呀?

 回到顶部
帅哥哟,离线,有人找我吗?
lpxjw_zyl
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:376 积分:4189 威望:0 精华:0 注册:2008/9/1 14:18:00
  发帖心情 Post By:2012/10/12 21:31:00 [只看该作者]

Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    For i As Integer = 0 To Sheet.Cols.Count -1
        If CurrentTable.Cols.Contains( Sheet(0,i).Value) = False Then
            MessageBox.Show("目标文件不含【" & Sheet(0,i).Value & "】列,请修改与目标文件一致!", "导入错误提示")
            Return
        End If
    Next
   
    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 sheet(r,c).Value = "" Then  Continue For

            If c > 0 Then
                Filter1 = Filter1 & " And "
            End If
            If CurrentTable.DataTable.DataCols(sheet(0,c).Value).IsNumeric Then
                Filter1 = Filter1 & sheet(0,c).Value & " = " & sheet(r,c).Value
            Else
                Filter1 = Filter1 & sheet(0,c).Value & " = '" & sheet(r,c).Value & "'"
            End If
        Next
'msgbox(filter1)
        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
End If


 回到顶部
帅哥哟,离线,有人找我吗?
lpxjw_zyl
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:376 积分:4189 威望:0 精华:0 注册:2008/9/1 14:18:00
  发帖心情 Post By:2012/10/12 21:37:00 [只看该作者]

Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    For i As Integer = 0 To Sheet.Cols.Count -1
        If CurrentTable.Cols.Contains( Sheet(0,i).Value) = False Then
            MessageBox.Show("目标文件不含【" & Sheet(0,i).Value & "】列,请修改与目标文件一致!", "导入错误提示")
            Return
        End If
    Next
   
    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
End If

 回到顶部
帅哥哟,离线,有人找我吗?
lpxjw_zyl
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:376 积分:4189 威望:0 精华:0 注册:2008/9/1 14:18:00
  发帖心情 Post By:2012/10/12 21:39:00 [只看该作者]

问题已解决

 

 

 

 

 


 回到顶部