以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  文件名问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=104878)

--  作者:HJG_HB950207
--  发布时间:2017/8/7 16:42:00
--  文件名问题
选择文件存入【距离】

Dim dlg As New OpenFileDialog 
dlg.Filter= "Excel文件|*.xls|Word文件|*.doc|Access文件|*.mdb" 
If dlg.ShowDialog = DialogResult.Ok Then 
    Dim ip As New Importer
ip.SourcePath = dlg.FileName 
ip.SourceTableName = "sHeeT1" 
ip.NewTableName ="距离" 
ip.Format = "Excel" 
ip.Import()
End If
请教:
选择文件后,如电子表格,如何判断所选文件有无“sheet1”的数据表?

--  作者:有点甜
--  发布时间:2017/8/7 16:47:00
--  
Dim dlg As New OpenFileDialog
dlg.Filter= "Excel文件|*.xls|Word文件|*.doc|Access文件|*.mdb"
If dlg.ShowDialog = DialogResult.Ok Then
    Dim book As new XLS.Book(dlg.FileName)
    Dim flag As Boolean = False
    For Each sheet As XLS.Sheet In book.Sheets
        If sheet.name = "sheet1" Then
            flag = True
        End If
    Next
    If flag Then
        Dim ip As New Importer
        ip.SourcePath = dlg.FileName
        ip.SourceTableName = "sheet1$"
        ip.NewTableName ="距离"
        ip.Format = "Excel"
        ip.Import()
    Else
        msgbox("不存在sheet1")
    End If
End If

--  作者:HJG_HB950207
--  发布时间:2017/8/7 16:49:00
--  
谢谢老师!