Foxtable(狐表)用户栏目专家坐堂 → [求助]这个问题怎么解决


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

主题:[求助]这个问题怎么解决

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


加好友 发短信
等级:童狐 帖子:290 积分:2931 威望:0 精华:0 注册:2008/9/29 10:13:00
  发帖心情 Post By:2021/1/7 21:44:00 [只看该作者]

19楼这个公式用导入方式直接导进表A,只保留汉字部分,如何修改?

 

Dim dt As DataTable = DataTables("表A")
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("Sheet1")
        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  dt.DataCols.Contains(sheet(0,c).Text.replace(" ", "")) Then
                nms.Add(sheet(0,c).Text.replace(" ", ""), c)
            End If
        Next
        For n As Integer = 1 To Sheet.Rows.Count -1
            Dim sfzhm As String = sheet(n,nms("xh")).Text
            Dim kc As String = sheet(n,nms("sfzh")).Text
            If sfzhm = "" Then Continue For
            Dim dr As DataRow = dt.Find("xh = '" & sfzhm & "' and sfzh = '" & kc & "'")
            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
                If dt.DataCols(m).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(m) = False
                    Else
                        key(m) = True
                    End If
                Else If dt.DataCols(m).Expression > "" Then
                    '表达式列
                Else If dt.DataCols(m).IsNumeric Then
                    key(m) = val(Sheet(dic(key),nms(m)).Value)
                Else If dt.DataCols(m).IsDate Then
                    Dim d As Date
                    If Date.TryParse(Sheet(dic(key),nms(m)).Value, d)
                        key(m) = d
                    End If
                   
                Else
                    key(m) = Sheet(dic(key),nms(m)).Value
                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
                If dt.DataCols(m).IsBoolean Then
                    If Sheet(l,nms(m)).Text = "" OrElse Sheet(l,nms(m)).Text = "False" OrElse Sheet(l,nms(m)).Value = 0 Then
                        ndr (m) = False
                    Else
                        ndr (m) = True
                    End If
                Else If dt.DataCols(m).Expression > "" Then
                    '表达式列
                Else If dt.DataCols(m).IsNumeric Then
                    ndr (m) = val(Sheet(l,nms(m)).Value)
                Else If dt.DataCols(m).IsDate Then
                    Dim d As Date
                    If Date.TryParse(Sheet(l,nms(m)).Value, d)
                        ndr (m) = d
                    End If
                Else
                   
                    ndr (m) = Sheet(l,nms(m)).Value
                End If
            Next
        Next
        dt.ResumeRedraw()
        'systemready = True
    End If
End If

[此贴子已经被作者于2021/1/7 21:44:57编辑过]

 回到顶部
总数 36 1 2 3 4 下一页