Foxtable(狐表)用户栏目专家坐堂 → 导入excel表 匹配字段后 且选择了是否唯一为是的接收字段后 怎么写判断 对应的接收字段值如果已经有了来源字段的内容时,跳过该行数据,避免重复值录入


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

主题:导入excel表 匹配字段后 且选择了是否唯一为是的接收字段后 怎么写判断 对应的接收字段值如果已经有了来源字段的内容时,跳过该行数据,避免重复值录入

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


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
导入excel表 匹配字段后 且选择了是否唯一为是的接收字段后 怎么写判断 对应的接收字段值如果已经有了来源字段的内容时,跳过该行数据,避免重复值录入  发帖心情 Post By:2021/11/19 0:59:00 [只看该作者]

导入excel表 匹配字段后  且选择了是否唯一为是的接收字段后  怎么写判断  对应的接收字段值如果已经有了来源字段的内容时,跳过该行数据,避免重复值录入图片点击可在新窗口打开查看

假定我的接收字段里面有一个身份证号  乡镇  单位列  想新增一个禁止重复身份证号 乡镇  单位的判断,实现当导入的数据如果表里已经有了一个身份证号或者其他设定了 是否唯一=是  的值之后,不在输入这个身份证号对应及其对应的整行数据,下述代码该怎么补充呢?
Dim r As Row
Dim i,j As Integer
Dim t1,t2 As Table
Dim str1,str2 As String
Dim str As String
t1 = Tables(Vars("btname11"))
t2 = e.form.Controls("Table1").Table
str1 = e.form.Controls("TextBox1").value
str2 = e.form.Controls("ComboBox1").value
Dim prb As WinForm.ProgressBar = e.Form.Controls("ProgressBar1")
If str1 = "" OrElse str2 = "" Then
    Return
End If
Dim Book As New XLS.Book(str1)
Dim Sheet As XLS.Sheet = Book.Sheets(str2)
If e.Form.Controls("CheckBox1").checked = False Then
    For Each r In t2.Rows
        If r.IsNull("来源字段") OrElse r.IsNull("接收字段") Then
            MessageBox.Show("字段匹配未完成!")
            Return
        End If
    Next
    prb.Visible = True
    prb.Maximum = Sheet.Rows.Count - 1
    For i = 1 To Sheet.Rows.Count -1
        r = t1.AddNew()
        For j = 0 To t2.Rows.count - 1
            'r(t2.Rows(j)(1)) = Sheet(i,j).Value
            Dim ss As String  =Sheet(i,t2.Rows(j)("来源列数")).Value


            r(t2.Rows(j)("接收字段")) = ss.Replace(" ", "").Trim
        Next
        prb.Value = i
    Next
Else
    For j = 0 To Sheet.Cols.count - 1
        If t1.cols.Contains(Sheet(0,j).value) Then
            If str = "" Then
                str = Sheet(0,j).value
                str = str.Replace(" ", "").Trim
            Else
                str = str & "," & Sheet(0,j).value
                str = str.Replace(" ", "").Trim
            End If
        End If
    Next
    If str = "" Then
        MessageBox.Show("对不起,没有匹配字段!")
        Return
    End If
    If MessageBox.Show("是否只导入匹配字段?","询问",MessageBoxButtons.YesNo,MessageBoxIcon.Question) = DialogResult.Yes Then
        prb.Visible = True
        prb.Maximum = Sheet.Rows.Count - 1
        For i = 1 To Sheet.Rows.Count -1
            r = t1.AddNew()
            For j = 0 To str.split(",").Length - 1
                Dim sss As String =Sheet(i,j).Value
                r(str.split(",")(j)) = sss.Replace(" ", "").Trim
            Next
            prb.Value = i
        Next
    Else
        Return
    End If
End If
t1.DataTable.save
MessageBox.Show("数据导入完毕!")
'e.Form.close

 回到顶部
总数 11 1 2 下一页