Foxtable(狐表)用户栏目专家坐堂 → [求助]设计导入器的时候 怎么定义导入空表时不报错


  共有2586人关注过本帖树形打印复制链接

主题:[求助]设计导入器的时候 怎么定义导入空表时不报错

帅哥哟,离线,有人找我吗?
leopain
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:172 积分:1188 威望:0 精华:0 注册:2015/8/5 16:45:00
[求助]设计导入器的时候 怎么定义导入空表时不报错  发帖心情 Post By:2015/9/21 15:40:00 [只看该作者]

'-----定义导入参数


'-----获取Excel文件名
Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
Dim bookName,sheetName As String


If dlg.ShowDialog = DialogResult.OK Then
    bookname = dlg.FileName
    e.Form.Controls("bookName").text = bookName
    '-----定义excel文件-----
    Dim Book As New XLS.Book(bookname)
    
    '------遍历表名-----
    For Each st As xls.sheet In book.sheets
        sheetName = sheetName & st.name & "|"
    Next
    
    
    '------设置默认值 
    Dim stname As WinForm.ComboBox = e.Form.Controls("sheetname")
    stname.combolist = sheetname.TrimEnd("|")
    stname.SelectedIndex = 0
    
    Dim btn As WinForm.Button = e.Form.Controls("读出数据")
    btn.PerformClick()
End If


这是我导入窗口的代码 
但是导入空表时会报错呢.

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/9/21 15:43:00 [只看该作者]

空表?指excel文件没有sheet?

 

stname.SelectedIndex = 0

 

改成

 

If stname.combolist = Nothing Then Return

stname.SelectedIndex = 0


 回到顶部
帅哥哟,离线,有人找我吗?
leopain
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:172 积分:1188 威望:0 精华:0 注册:2015/8/5 16:45:00
  发帖心情 Post By:2015/9/21 15:46:00 [只看该作者]

是指sheet里没数据.. 我今天导入时点错点到了一个新建excel文件 出现报错

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/9/21 15:49:00 [只看该作者]

贴出按钮的代码,贴出报的错误。


 回到顶部
帅哥哟,离线,有人找我吗?
leopain
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:172 积分:1188 威望:0 精华:0 注册:2015/8/5 16:45:00
  发帖心情 Post By:2015/9/21 16:03:00 [只看该作者]


 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:导入excel_201509211553.zip



 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/9/21 16:22:00 [只看该作者]

按钮代码

 

Dim bookname As WinForm.TextBox = e.Form.Controls("bookName")
If bookname.Value = "" Then
   
    MessageBox.show("请点击 [Excel文件] 按钮,选取Excel文件! ","错误提示",MessageBoxButtons.OK,MessageBoxIcon.Error)
    Return
End If

Dim sheetname As WinForm.ComboBox = e.Form.Controls("sheetname")
If sheetname.SelectedValue = "" Then
    MessageBox.show("导入工作表不能为空 ! ","错误提示",MessageBoxButtons.OK,MessageBoxIcon.Error)
    Return
End If

Dim Book As New XLS.Book(bookname.text)
Dim sheet As XLS.Sheet = book.sheets(sheetname.SelectedValue)
Dim bt As WinForm.CheckBox = e.Form.Controls("标题")
'设定最大取值列
Dim maxc As WinForm.NumericComboBox = e.Form.Controls("最大列")
If maxc.value > sheet.Cols.Count Or maxc.value = 0 Then
    maxc.Value = sheet.Cols.Count
End If
Dim qsh As WinForm.NumericComboBox = e.Form.Controls("有效起始行")
Dim cblst As String
'------遍历数据-----
Dim qs As Integer = cint(qsh.Text)
For r As Integer = qs-1 To qs+6
    Dim lst As String = ""
    For c As Integer = 0 To maxc.value - 1
        Dim data As String = sheet(r,c).value
        lst = lst & data.PadLeft(8," ") & ","
    Next
    cblst = cblst & lst & "|"
Next
'-----标题-----'
Dim h As String

Dim cbl As String = ""


For c As Integer = 0 To maxc.Value -1
    h = "第" & cstr(c+1) & "列"
    If bt.Checked Then
        cbl = cbl & h & "-->" & sheet(qs-1,c).Text & "|"
    Else
        cbl = cbl & h & "|"
    End If
Next
Dim lst5r As WinForm.ListBox = e.Form.Controls("lst5r")
lst5r.ComboList = cblst
e.Form.Controls("表字段0").combolist = cbl.TrimEnd("|")

'dcl.ComboList = cbl.TrimEnd("|")


 回到顶部