Foxtable(狐表)用户栏目专家坐堂 → [求助]选择EXCEL,当有密码时出错


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

主题:[求助]选择EXCEL,当有密码时出错

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


加好友 发短信
等级:四尾狐 帖子:953 积分:7252 威望:0 精华:0 注册:2011/9/6 13:36:00
[求助]选择EXCEL,当有密码时出错  发帖心情 Post By:2015/6/24 11:24:00 [显示全部帖子]

Dim dlg As New OpenFileDialog
dlg.Filter= "Excel 97-2003文件(*.xls)|*.xls|Excel 2007文件(*.xlsx)|*.xlsx"
If dlg.ShowDialog = DialogResult.Ok Then
    Dim cmb1 As WinForm.ComboBox = e.Form.Controls("ComboBox1")
    Dim txtb1 As WinForm.TextBox = e.Form.Controls("TextBox1")
    txtb1.value = dlg.FileName
    cmb1.Value = ""
    If txtb1.Value > "" Then
        Book = New XLS.Book(txtb1.value)
        cmb1.items.clear
        Dim str(Book.Sheets.count - 1) As String
        Dim Sheet As XLS.Sheet
        For i As Integer = 0 To Book.Sheets.count - 1
            str(i) = Book.Sheets(i).name ' str.add(Book.Sheets(i).name)
        Next
        cmb1.Items.AddRange(str)
    End If
    cmb1.Select()
End If

 

有密码时出错:

.NET Framework 版本:2.0.50727.3655
Foxtable 版本:2014.11.11.1
错误所在事件:窗口,Excel导入,Button1,Click
详细错误信息:
Object reference not set to an instance of an object.

 

 


怎么提前判断是否有密码?


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


加好友 发短信
等级:四尾狐 帖子:953 积分:7252 威望:0 精华:0 注册:2011/9/6 13:36:00
  发帖心情 Post By:2015/6/24 11:38:00 [显示全部帖子]

OK!已解决!谢谢!

Dim dlg As New OpenFileDialog
dlg.Filter= "Excel 97-2003文件(*.xls)|*.xls|Excel 2007文件(*.xlsx)|*.xlsx"
If dlg.ShowDialog = DialogResult.Ok Then
    Dim cmb1 As WinForm.ComboBox = e.Form.Controls("ComboBox1")
    Dim txtb1 As WinForm.TextBox = e.Form.Controls("TextBox1")
    txtb1.value = dlg.FileName
    cmb1.Value = ""
    If txtb1.Value > "" Then
        Try
            Book = New XLS.Book(txtb1.value)
            cmb1.items.clear
            Dim str(Book.Sheets.count - 1) As String
            Dim Sheet As XLS.Sheet
            For i As Integer = 0 To Book.Sheets.count - 1
                str(i) = Book.Sheets(i).name ' str.add(Book.Sheets(i).name)
            Next
            cmb1.Items.AddRange(str)
        catch ex As exception
            MessageBox.Show("打开Excel文件出错!" & vbcrlf & vbcrlf & "如果Excel文件有密码,请去掉密码后再导入!")
            txtb1.value = Nothing
        End try
    End If
    cmb1.Select()
End If


 回到顶部