以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  代码问题求指教?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=76150)

--  作者:lisheng7177
--  发布时间:2015/10/22 15:46:00
--  代码问题求指教?

在窗品事件中加入下面代码,结果导入就出问题,无数据导入,只有空白行增加!这是为什么,在这之前都是正常的?

Tables("证书编号表").Sort = "鉴定批次,鉴定等级,证书编号"

 

“导入”按钮代码:

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(0)
        Tables("证书编号表").ResumeRedraw()
        Tables("证书编号表").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
            Dim str As String = sheet(1,c).Text.Replace(" ", "")
            If  DataTables("证书编号表").DataCols.Contains(str) Then
                nms.Add(str, c)
            End If
        Next
        For n As Integer = 2 To Sheet.Rows.Count -1
            Dim sfzhm As String = sheet(n,5).Text
            Dim jdpc As String = sheet(n,9).Text
            Dim dr As DataRow = DataTables("证书编号表").Find("身份证号码 = \'" & sfzhm & "\' And 鉴定批次 = \'" & jdpc & "\'")
            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 DataTables("证书编号表").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 DataTables("证书编号表").DataCols(m).Expression > "" Then
                    \'表达式列
                Else If DataTables("证书编号表").DataCols(m).IsNumeric Then
                    key(m) = val(Sheet(dic(key),nms(m)).Value)
                Else
                    key(m) = Sheet(dic(key),nms(m)).Value
                End If
            Next
        Next
        For Each l As Integer In ls
            Dim ndr As DataRow = DataTables("证书编号表").AddNew
            For Each m As String In nms.keys
                If DataTables("证书编号表").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 DataTables("证书编号表").DataCols(m).Expression > "" Then
                    \'表达式列
                Else If DataTables("证书编号表").DataCols(m).IsNumeric Then
                    ndr (m) = val(Sheet(l,nms(m)).Value)
                Else
                    ndr (m) = Sheet(l,nms(m)).Value
                End If
            Next
        Next
        Tables("证书编号表").ResumeRedraw()
        systemready = True
    End If
End If


--  作者:大红袍
--  发布时间:2015/10/22 15:53:00
--  

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

 

改成

 

Dim Sheet As XLS.Sheet = Book.Sheets("表A")


--  作者:lisheng7177
--  发布时间:2015/10/22 15:57:00
--  

一切OK了,谢谢版主!!!!!!