以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  EXCEL为空的问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=89459)

--  作者:wh420
--  发布时间:2016/8/22 15:48:00
--  EXCEL为空的问题
以下代码段落执行有内容的EXCEL时正常,但如果我新建一个EXCEL,里面没有任何内容的情况下程序报“未设置对象变量勤WITH块变量

Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(file)
        
        For k As Integer = 1 To wb.workSheets.Count \'//多个sheet的处理
            Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(k)
            Dim Rg As MSExcel.Range = Ws.UsedRange
            Dim ary = rg.value
            
            For i As Integer = 1 To rg.Rows.Count
                For j As Integer = 1 To rg.Columns.Count
                    
                    If ary(i,j) <> Nothing Then
                        
                        If Forms("提取工具").Controls("CBox").Checked = True  AndAlso System.Text.RegularExpressions.Regex.Match((ary(i,j)),"[\\u4e00-\\u9fa5]+").Tostring()>"" =True Then
                            Dim dr As DataRow = DataTables("表A").AddNew
                            dr("c2") = ary(i,j)
                             ................


--  作者:大红袍
--  发布时间:2016/8/22 16:10:00
--  

Dim app As new MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("d:\\test.xls")

For k As Integer = 1 To wb.workSheets.Count \'//多个sheet的处理
    Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(k)
    Dim Rg As MSExcel.Range = Ws.UsedRange
    Dim ary = rg.value
    If ary IsNot Nothing Then
        For i As Integer = 1 To rg.Rows.Count
            For j As Integer = 1 To rg.Columns.Count
                If ary(i,j) <> Nothing Then
                End If
            Next
        Next
    End If
Next
app.quit


--  作者:wh420
--  发布时间:2016/8/22 16:46:00
--  
问题解决,多谢红袍老师