Foxtable(狐表)用户栏目专家坐堂 → 求助,无条件合并导入怎么添加弹窗


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

主题:求助,无条件合并导入怎么添加弹窗

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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/20 16:47:00 [显示全部帖子]

参考

 

下载信息  [文件大小:31.3 KB  下载次数:7]
图片点击可在新窗口打开查看点击浏览该文件:导入excel文件.zip


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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/20 16:51:00 [显示全部帖子]

看3楼。

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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/20 17:51:00 [显示全部帖子]

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:导入excel文件(不同列名).zip


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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/21 17:05:00 [显示全部帖子]

看懂代码,前面那里,就是啊

 

Dim dt As DataTable = DataTables("认证报名表")
Dim zj As String = "身份证号码"
Dim 列名() As String = {"申请类别", "申报级别", "身份证号码"}
Dim excel列() As String = {"申报类别", "申报级别", "身份证号码"}

Dim Result As DialogResult
Result = MessageBox.Show("确定要导入吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
    Dim dlg As New OpenFileDialog
    dlg.Filter = "Excel文件|*.xls"
    dlg.MultiSelect = True '允许选择多个文件
    If dlg.ShowDialog =DialogResult.OK Then
        Dim Book As New XLS.Book(dlg.FileName)
        Dim Sheet As XLS.Sheet = Book.Sheets("认证报名表")
        dt.ResumeRedraw()
        dt.StopRedraw()
        'systemready = False
        Dim nms As New Dictionary(Of String, Integer)
        Dim dic As new Dictionary(Of DataRow, Integer)
        Dim ls As new List(Of Integer)
        For c As Integer = 0 To sheet.Cols.Count - 1
            If sheet(0,c).Text.replace(" ", "") > "" Then
                'If dt.DataCols.Contains(sheet(0,c).Text.replace(" ", "")) Then
                nms.Add(sheet(0,c).Text.replace(" ", ""), c)
                'End If
            End If
        Next
        For n As Integer = 1 To Sheet.Rows.Count -1
            Dim sfzhm As String = sheet(n,nms(zj)).Text
            If sfzhm = "" Then Continue For
            Dim dr As DataRow = dt.Find("身份证号码 = '" & sfzhm & "'")
            If dr Is Nothing Then
                ls.add(n)
            Else
                dic.Add(dr, n)
            End If
        Next
        For Each key As DataRow In dic.Keys
            For Each m As String In nms.keys
                Dim idx As Integer = array.Indexof(excel列, m)
                If idx >= 0 Then
                    Dim cname As String = 列名(idx)
                    If dt.DataCols(cname).IsBoolean Then
                        If Sheet(dic(key),nms(m)).Text = "" OrElse Sheet(dic(key),nms(m)).Text = "False" OrElse Sheet(dic(key),nms(m)).Value = 0 Then
                            key(cname) = False
                        Else
                            key(cname) = True
                        End If
                    Else If dt.DataCols(cname).Expression > "" Then
                        '表达式列
                    Else If dt.DataCols(cname).IsNumeric Then
                        key(cname) = val(Sheet(dic(key),nms(m)).Value)
                    Else If dt.DataCols(cname).IsDate Then
                        Dim d As Date
                        If Date.TryParse(Sheet(dic(key),nms(m)).Value, d)
                            key(cname) = d
                        End If
                       
                    Else
                        key(cname) = Sheet(dic(key),nms(m)).Value
                    End If
                End If
            Next
        Next
        For Each l As Integer In ls
            Dim ndr As DataRow = dt.AddNew
            For Each m As String In nms.keys
                Dim idx As Integer = array.Indexof(excel列, m)
                If idx >= 0 Then
                    Dim cname As String = 列名(idx)
                    If dt.DataCols(cname).IsBoolean Then
                        If Sheet(l,nms(m)).Text = "" OrElse Sheet(l,nms(m)).Text = "False" OrElse Sheet(l,nms(m)).Value = 0 Then
                            ndr (cname) = False
                        Else
                            ndr (cname) = True
                        End If
                    Else If dt.DataCols(cname).Expression > "" Then
                        '表达式列
                    Else If dt.DataCols(cname).IsNumeric Then
                        ndr (m) = val(Sheet(l,nms(m)).Value)
                    Else If dt.DataCols(cname).IsDate Then
                        Dim d As Date
                        If Date.TryParse(Sheet(l,nms(m)).Value, d)
                            ndr (cname) = d
                        End If
                    Else
                        ndr (cname) = Sheet(l,nms(m)).Value
                    End If
                End If
            Next
        Next
        dt.ResumeRedraw()
        'systemready = True
    End If
End If


 回到顶部