以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  导入不成功  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=85986)

--  作者:aidimeng
--  发布时间:2016/6/7 14:21:00
--  导入不成功

Dim dlg As new OpenFileDialog
If dlg.ShowDialog = DialogResult.OK Then
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
   
   
   
    Tables("A110信息登记_明细").StopRedraw()
    \'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
    Dim nms() As String = {"流水号","报警时间","报警电话","报警人","报警类别","辖区","事发地点","报警内容"}
    \'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
    For n As Integer = 1 To Sheet.Rows.Count -1
        Dim bh As String = sheet(n,0).Text \'取得流水号
       
        If DataTables("A110信息登记_明细").Find("流水号= \'" & bh & "\'") Is Nothing Then
           
            For m As Integer = 0 To nms.Length - 1
 
                If Sheet(n,m).Text <> "" Then
                    Dim r As Row = Tables("窗口1_table1").AddNew()
                    \'MessageBox.Show( r("\'"& nms(m) &"\'"))
                   
                    r(nms(m)) = Sheet(n,m).Value
                    
                End If
            Next
        End If
    Next
    Tables("A110信息登记_明细").ResumeRedraw()
End If

 

导入两行空白行。不知道错在哪里


--  作者:Hyphen
--  发布时间:2016/6/7 14:58:00
--  
看不出什么问题,上传例子测试
--  作者:大红袍
--  发布时间:2016/6/8 10:29:00
--  

1、是不是你导入的数据都已经有了?

 

2、代码

 

Dim dlg As new OpenFileDialog
If dlg.ShowDialog = DialogResult.OK Then
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
   
   
   
    Tables("A110信息登记_明细").StopRedraw()
    \'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
    Dim nms() As String = {"流水号","报警时间","报警电话","报警人","报警类别","辖区","事发地点","报警内容"}
    \'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
    For n As Integer = 1 To Sheet.Rows.Count -1
        Dim bh As String = sheet(n,0).Text \'取得流水号
       
        If DataTables("A110信息登记_明细").Find("流水号= \'" & bh & "\'") Is Nothing Then
            Dim r As Row = Tables("窗口1_table1").AddNew()
            For m As Integer = 0 To nms.Length - 1
               
                If Sheet(n,m).Text.Trim <> "" Then
                                     
                    r(nms(m)) = Sheet(n,m).Text.Trim
                    
                End If
            Next
        End If
    Next
    Tables("A110信息登记_明细").ResumeRedraw()
End If