以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  excel导入问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=74685)

--  作者:sloyy
--  发布时间:2015/9/16 17:55:00
--  excel导入问题

帮助里面有一段:

Dim ip as New Importer
ip
.SourcePath = "c:\\Data\\销售管理.xls" \'指定数据文件
ip
.SourceTableName = "订单$" \'指定要导入的表
ip
.NewTableName ="订单" \'导入后的表名
ip.Format = "Excel"
\'指定导入格式

ip
.Import()


如果要导入的表名字不知道,只知道它是第一个表,该怎么导入?


--  作者:大红袍
--  发布时间:2015/9/16 17:56:00
--  
用xls.book打开excel,获取表名。
--  作者:sloyy
--  发布时间:2015/9/17 0:39:00
--  

    Dim dlg As New OpenFileDialog
    dlg.Filter="Excel文件|*.xls;*.xlsx"
        If dlg.ShowDialog = DialogResult.Ok Then
           Dim ip As New Importer
            ip.SourcePath = dlg.FileName \'指定数据文件
            Dim App As New MSExcel.Application
            Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName )
            Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
            ip.SourceTableName = Ws.Name & "$"  \'指定要导入的表
             App.Quit
            ip.NewTableName ="订单"      \'导入后的表名
            ip.Format = "Excel" \'指定导入格式
            ip.Import()
        end if