以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [分享] 窗口表导入EXCEL数据  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=53022)

--  作者:blackzhu
--  发布时间:2014/6/27 16:04:00
--  [分享] 窗口表导入EXCEL数据
做个窗口,放入一个表控件,做一个按钮测试:

 Dim TableName as string = "窗口1_Table1"
 Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog
        dlg.Filter = "Excel文件|*.xls|Word文件|*.doc|Access文件|*.mdb"
        If dlg.ShowDialog = DialogResult.OK Then \'如果用户单击了确定按钮
            Dim Book As New XLS.Book(dlg.FileName)
            Dim Sheet As XLS.Sheet = Book.Sheets(0)
            Tables(TableName).StopRedraw()
            Dim dtb As New DataTableBuilder("统计")
            For n1 As Integer = 1 To Sheet.Cols.Count - 1
                dtb.AddDef(Sheet(0, n1).Text, GetType(String), 32)
            Next
            Tables(TableName).DataSource = dtb.BuildDataSource
            For n As Integer = 1 To Sheet.Rows.Count - 1
                Dim bh As String = Sheet(n, 0).Text
                Dim dr As Row = Tables(TableName).AddNew()
                For m As Integer = 0 To Tables(TableName).Cols.Count - 1
                    dr(Tables(TableName).Cols(m)) = Sheet(n, m).Value
                Next
            Next
            Tables(TableName).ResumeRedraw()

--  作者:Bin
--  发布时间:2014/6/27 16:09:00
--  
谢谢分享
--  作者:jxkqf
--  发布时间:2014/6/27 22:30:00
--  
不错
--  作者:good131577
--  发布时间:2014/6/27 23:39:00
--  
为什么我按照一样写 一点就卡死掉~
窗口名称叫 当天配送会员窗口  加了个 Table 名称是默认的Table1  然后加了个button控件 下面是写在Click事件里面的~
Dim TableName As String = "当天配送会员窗口_Table1"
Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog
dlg.Filter = "Excel文件|*.xls|Word文件|*.doc|Access文件|*.mdb"
If dlg.ShowDialog = DialogResult.OK Then \'如果用户单击了确定按钮
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    Tables(TableName).StopRedraw()
    Dim dtb As New DataTableBuilder("统计")
    For n1 As Integer = 1 To Sheet.Cols.Count - 1
        dtb.AddDef(Sheet(0, n1).Text, Gettype(String), 32)
    Next
    Tables(TableName).DataSource = dtb.BuildDataSource
    For n As Integer = 1 To Sheet.Rows.Count - 1
        Dim bh As String = Sheet(n, 0).Text
        Dim dr As Row = Tables(TableName).AddNew()
        For m As Integer = 0 To Tables(TableName).Cols.Count - 1
            dr(Tables(TableName).Cols(m)) = Sheet(n, m).Value
        Next
    Next
    Tables(TableName).ResumeRedraw()
End If
一点按钮就卡死了??

--  作者:zyqzyy
--  发布时间:2014/6/27 23:57:00
--  
Dim TableName As String = "窗口2_Table1"
Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog
dlg.Filter = "Excel文件|*.xls|Word文件|*.doc|Access文件|*.mdb"
If dlg.ShowDialog = DialogResult.OK Then \'如果用户单击了确定按钮
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    Tables(TableName).StopRedraw()
    Dim dtb As New DataTableBuilder("统计")
    For n1 As Integer = 1 To Sheet.Cols.Count - 1
        dtb.AddDef(Sheet(0, n1).Text, Gettype(String), 32)
    Next
    Tables(TableName).DataSource = dtb.BuildDataSource
    For n As Integer = 1 To Sheet.Rows.Count - 1
        Dim bh As String = Sheet(n, 0).Text
        Dim dr As Row = Tables(TableName).AddNew()
        For m As Integer = 0 To Tables(TableName).Cols.Count - 1
            dr(Tables(TableName).Cols(m)) = Sheet(n, m).Value
        Next
    Next
End If
Tables(TableName).ResumeRedraw()

--  作者:zyqzyy
--  发布时间:2014/6/28 0:21:00
--  

请教楼主,如何与外部表对比后导入不重复的记录?