以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  关于合并导入的问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=72804)

--  作者:扶风
--  发布时间:2015/8/6 15:21:00
--  关于合并导入的问题

老师  如下合并导入代码  为何执行后会有一列没有数据呢  表中列名与EXCEL列名是一致的啊

 

Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
    Dim mg As New Merger
    mg.Format = "Excel"
    mg.SourcePath = dlg.FileName
    mg.SourceTableName = "Page1"
    mg.DataTableName = "物料表"
    mg.Merge()
End If

For Each dt As DataTable In DataTables
    dt.Save()
Next

MessageBox.Show("合并导入成功!","提示")


--  作者:大红袍
--  发布时间:2015/8/6 15:23:00
--  

 要编写代码导入才行

 

http://www.foxtable.com/help/topics/2334.htm

 


--  作者:扶风
--  发布时间:2015/8/6 15:28:00
--  

其他列都是OK的

  我试试先  谢谢老师


--  作者:大红袍
--  发布时间:2015/8/6 15:28:00
--  

参考代码

 

Dim dlg As new OpenFileDialog
dlg.MultiSelect = True
If dlg.ShowDialog = DialogResult.OK Then
    For Each f As String In dlg.FileNames
        Dim  Book As New XLS.Book(f)
        Dim Sheet As XLS.Sheet = Book.Sheets(0)
        Dim dic As new Dictionary(Of String, Integer)
        For i As Integer = 0 To sheet.Cols.Count - 1
            If sheet(0,i).Text <> Nothing
                dic.Add(sheet(0,i).Text,i)
            End If
        Next
        For  n As Integer = 1 To Sheet.Rows.Count -1
            Dim dr As DataRow =  DataTables("表A").AddNew()
            For Each c As String In dic.Keys
                If DataTables("表A").datacols.Contains(c) Then
                    dr(c) = sheet(n, dic(c)).Text
                End If
            Next
        Next
    Next
   
End If


--  作者:扶风
--  发布时间:2015/8/6 16:22:00
--  
好的 谢谢老师  已经OK了