Foxtable(狐表)用户栏目专家坐堂 → word报告生成效率问题


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

主题:word报告生成效率问题

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


加好友 发短信
等级:一尾狐 帖子:485 积分:4075 威望:0 精华:0 注册:2015/12/16 8:22:00
word报告生成效率问题  发帖心情 Post By:2017/8/8 15:09:00 [只看该作者]

If e.Form.Controls("DateTimePicker3").value Is Nothing Then
    MessageBox.Show("完成日期:" & "不能为空,请检查")
    e.Cancel = True
Else
    If Tables("T_Report").current IsNot Nothing Then
        DataTables("T_Report").ReplaceFor("报告状态",True,"[报告编号] = '" & Tables("T_Report").current("报告编号") & "'")
    End If
    Tables("T_Report").Current.save()
    Dim bh As String = Tables("T_Report").Current("报告格式编号")
    Dim tm As String  = ProjectPath & "Attachments\" & bh & ".doc" '指定模板文件
    Dim fl As String = ProjectPath & "Reports\" & Tables("T_Report").current("报告编号") & " " & Tables("T_Report").current("样品名称") & ".Doc" '指定目标文件
    Dim wrt As New WordReport(Tables("T_Report"),tm,fl) '定义一个WordReport
    Tables("T_Report.T_Item").Sort = "报告序号"
    For i As Integer = 0 To Tables("T_Report.T_Item").Rows.count - 1
        Dim r As Row = Tables("T_Report.T_Item").Rows(i)
        wrt.ReplaceOne("[报告序号" & i & "]", r("报告序号"))
    Next
    wrt.BuildOne(Tables("T_Report").Current)
    wrt.Quit
    Dim app As New MSWord.Application
    try
        Dim fileName = ProjectPath & "Reports\" & Tables("T_Report").current("报告编号") & " " & Tables("T_Report").current("样品名称") & ".Doc"
        Dim doc As Object = app.Documents.Open(fileName)
        
        app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader
        If app.Selection.Find.Execute("CTTREPORT") Then '查找到指定字符串
            app.Selection.Text =" " & Tables("T_Report").current("报告编号") & "" '替换字符串
        End If
        app.ActiveWindow.ActivePane.View.SeekView =  MSWord.WdSeekView.wdSeekMainDocument
        
        app.Visible = True
    catch ex As exception
        msgbox(ex.message)
        app.Quit
    finally
        'app.Quit
    End try
End If

我是通过以上的代码来生成报告模板的,但在点击按钮之后一般都是要等大约20s左右才能生成,请问有没有优化的空间?

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/8/8 15:16:00 [只看该作者]

加入msgbox,看是哪一步耗时,耗时代码包括 ReplaceFor、save、Sort 等

 

其余的,就不能优化了。


 回到顶部