以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  Importer  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=59079)

--  作者:shanmao
--  发布时间:2014/10/29 13:24:00
--  Importer
Importer方法可以放在for each 里循环导入吗?我导入excel表中的sheet1可以,导入sheet2,sheet3都会提示运行错误。

图片点击可在新窗口打开查看此主题相关图片如下:333.png
图片点击可在新窗口打开查看


--  作者:狐狸爸爸
--  发布时间:2014/10/29 13:41:00
--  
贴出你的代码
--  作者:shanmao
--  发布时间:2014/10/29 14:03:00
--  
Dim MyBook As New C1Excel.C1XLBook  \'当前的Book
Dim str As String
Dim i,bi As Integer
i = 0
bi = 0
Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog
dlg.Filter= "Excel文件|*.xlsx|Excel文件|*.xls|Word文件|*.doc|Access文件|*.mdb" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
    Dim ip As New Importer
    ip.SourcePath = dlg.FileName \'指定数据文件
    MyBook.load(dlg.FileName)
    For Each sheet As C1Excel.XLSheet In MyBook.Sheets()
        str = sheet.name
        If i = bi Then
            ip.SourceTableName = str \'指定要导入的表
            ip.NewTableName = str \'导入后的表名
            ip.Format = "Excel" \'指定导入格式
            MessageBox.Show(ip.SourceTableName & "\\" & ip.NewTableName &"\\"& ip.Format)
            ip.Import()
            i += 1
            bi = i
        End If
    Next
End If

--  作者:有点甜
--  发布时间:2014/10/29 14:28:00
--  
Dim MyBook As New C1Excel.C1XLBook  \'当前的Book
Dim str As String
Dim i,bi As Integer
i = 0
bi = 0
Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog
dlg.Filter= "Excel文件|*.xlsx|Excel文件|*.xls|Word文件|*.doc|Access文件|*.mdb" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
   
    MyBook.load(dlg.FileName)
    For Each sheet As C1Excel.XLSheet In MyBook.Sheets()
        str = sheet.name
        If i = bi Then
            Dim ip As New Importer
            ip.SourcePath = dlg.FileName \'指定数据文件
            ip.SourceTableName = str \'指定要导入的表
            ip.NewTableName = str \'导入后的表名
            ip.Format = "Excel" \'指定导入格式
            MessageBox.Show(ip.SourceTableName & "\\" & ip.NewTableName &"\\"& ip.Format)
            ip.Import()
            i += 1
            bi = i
        End If
    Next
End If

--  作者:cha618
--  发布时间:2016/4/21 16:05:00
--  
这段代码如果目标表有 三个工作表则全部导入数据了

这段代码  如何 改成 让用户 选择导入 哪一个数据表

或者 进行询问是否导入,点是后才导入



--  作者:大红袍
--  发布时间:2016/4/21 16:12:00
--  
Dim dlg As new OpenFileDialog
dlg.Filter = "Excel|*.xls;*.xlsx"
If dlg.ShowDialog = DialogResult.OK Then
    Dim book As new XLS.Book(dlg.FileName)
    For Each sheet As XLS.Sheet In book.Sheets
        Dim Result As DialogResult
        Result = MessageBox.Show("是否要导入" & sheet.name & "表", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If Result = DialogResult.Yes Then
            Dim ip As New Importer
            ip.SourcePath = dlg.FileName
            ip.SourceTableName =  sheet.Name & "$" \'指定要导入的表
            ip.NewTableName = sheet.name.trim()  \'导入后的表名
            ip.Format = "Excel" \'指定导入格式
            ip.Import()
        End If
    Next
End If

--  作者:凡夫俗子
--  发布时间:2016/4/21 22:15:00
--  
这个功能怎么就不能选择列再导入呢
--  作者:大红袍
--  发布时间:2016/4/22 0:24:00
--  
以下是引用凡夫俗子在2016/4/21 22:15:00的发言:
这个功能怎么就不能选择列再导入呢

 

你可以单独做一个窗口,读取第一行的值作为列选择,然后控制 Fields

 

Fields


指定要导入的字段(列),不同的字段,用逗号给开,如果不指定,则导入所有字段。


--  作者:凡夫俗子
--  发布时间:2016/4/22 6:45:00
--  
好如果已有Fieds参数字符串如何在导入时加入这个参数
--  作者:Hyphen
--  发布时间:2016/4/22 8:35:00
--  
c参考:http://www.foxtable.com/help/topics/0684.htm