Foxtable(狐表)用户栏目专家坐堂 → 老师帮忙看看程序问题


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

主题:老师帮忙看看程序问题

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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/8/26 15:28:00 [显示全部帖子]

Dim st As Date = Date.Now
Dim lbl As WinForm.Label = Forms("提取工具").Controls("Label6")
Dim path As String = args(0)
Dim lbl2 As WinForm.Label = Forms("提取工具").Controls("Label2")
Dim Cbox1 As WinForm.CheckBox = Forms("提取工具").Controls("CBox")
Dim Cbox2 As WinForm.CheckBox = Forms("提取工具").Controls("CBox2")
Dim file As Object

Dim app As new MSExcel.Application
For Each file In FileSys.GetFiles(path)
    try
        Dim wb = 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
                If rg.Rows(i).height <> 0 Then
                    For j As Integer = 1 To rg.Columns.Count
                        If rg.Columns(j).width <> 0 Then
                            If ary(i,j) <> Nothing Then
                                If CBox1.Checked = True AndAlso Cbox2.Checked=False AndAlso System.Text.RegularExpressions.Regex.Match(ary(i,j),"[\u4e00-\u9fa5]+").Tostring()>""
                                    Dim dr As DataRow = DataTables("表A").AddNew
                                    dr("第一列") = ary(i, j)
                                End If
                            End If
                        End If
                    Next
                End If
            Next
        Next
        Dim txt1 As WinForm.TextBox = Forms("提取工具").Controls("TextBox3")
        txt1.text = file & vbcrlf & txt1.text & vbcrlf
        Application.DoEvents()
        ' FileCount=FileCount+1
        'lbl.Text="已提取" & FileCount & "个文件,未提取 " & BadFileCount & "个文件"
        app.quit
    Catch ex As Exception
        'MessageBox.show("当前目录不存在或文件有问题,请检查!","提示")
        msgbox(ex.message)
        Dim txt2 As WinForm.TextBox = Forms("提取工具").Controls("TextBox4")
        txt2.text = file & vbcrlf & txt2.text & vbcrlf
        'BadFileCount =BadFileCount +1
        app.quit
    End try
Next

For Each p As String In FileSys.GetDirectories(path)
    Functions.Execute("提取测试", p)
Next
lbl2.Text="计算结束, 耗时: " & (Date.Now - st).TotalSeconds & "秒"


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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/8/26 16:07:00 [显示全部帖子]

 必须用 MSExcel

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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/8/26 16:50:00 [显示全部帖子]

以下是引用wh420在2016/8/26 16:23:00的发言:
哦,好吧。我其实两种方法都想用,但MSEXCEL方式已经调试好了,结果XLS.BOOK怎么也不通过,不是丢数据就是判断不出来,如果可以还请老师多说说这是咋回事。

 

XLS.Book获取到的信息不准确的。


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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/8/26 16:55:00 [显示全部帖子]

Dim st As Date = Date.Now
Dim lbl As WinForm.Label = Forms("提取工具").Controls("Label6")
Dim path As String = args(0)
Dim lbl2 As WinForm.Label = Forms("提取工具").Controls("Label2")
Dim Cbox1 As WinForm.CheckBox = Forms("提取工具").Controls("CBox")
Dim Cbox2 As WinForm.CheckBox = Forms("提取工具").Controls("CBox2")
Dim file As Object

Dim app As new MSExcel.Application
For Each file In FileSys.GetFiles(path)
    try
        Dim wb = 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
                If CBox2.Checked OrElse rg.Rows(i).height <> 0 Then
                    For j As Integer = 1 To rg.Columns.Count
                        If CBox2.Checked OrElse rg.Columns(j).width <> 0 Then
                            If ary(i,j) <> Nothing Then
                                If CBox1.Checked = False OrElse CBox1.Checked = True AndAlso System.Text.RegularExpressions.Regex.Match(ary(i,j),"[\u4e00-\u9fa5]+").Tostring()>""
                                    Dim dr As DataRow = DataTables("表A").AddNew
                                    dr("第一列") = ary(i, j)
                                End If
                            End If
                        End If
                    Next
                End If
            Next
        Next
        Dim txt1 As WinForm.TextBox = Forms("提取工具").Controls("TextBox3")
        txt1.text = file & vbcrlf & txt1.text & vbcrlf
        Application.DoEvents()
        ' FileCount=FileCount+1
        'lbl.Text="已提取" & FileCount & "个文件,未提取 " & BadFileCount & "个文件"
        app.quit
    Catch ex As Exception
        'MessageBox.show("当前目录不存在或文件有问题,请检查!","提示")
        msgbox(ex.message)
        Dim txt2 As WinForm.TextBox = Forms("提取工具").Controls("TextBox4")
        txt2.text = file & vbcrlf & txt2.text & vbcrlf
        'BadFileCount =BadFileCount +1
        app.quit
    End try
Next

For Each p As String In FileSys.GetDirectories(path)
    Functions.Execute("提取测试", p)
Next
lbl2.Text="计算结束, 耗时: " & (Date.Now - st).TotalSeconds & "秒"


 回到顶部