以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  WordReport批量导出单个文件,程序卡死  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=137163)

--  作者:xluoping
--  发布时间:2019/6/29 11:10:00
--  WordReport批量导出单个文件,程序卡死
代码如下:

导出不到30个文件,程序就卡死了,不能继续导出,请问问题出在哪里?请指教

For Each dr As Row In Tables("MSDS").Rows \'逐行生成报表
    Dim tm As String  = ProjectPath & "Attachments\\MSDS.docx" \'指定模板文件
    Dim st As String =  dr("ICSC编号") & "-" & dr("名称") & "-" & "国际化学品安全卡MSDS.docx"
    st = st.Replace(" ","")
    dr("文件名") = st
    If FileSys.FileExists(ProjectPath & "Reports\\"& st) = false then
        Dim fl As String = ProjectPath & "Reports\\"& st   \'指定目标文件
        Dim wrt As New WordReport(Tables("MSDS"),tm,fl) \'定义一个WordReport
        wrt.BuildOne(dr)
        \'wrt.Replace("^13^13","^13")
        wrt.Quit() \'退出
        \' wrt.Show() \'显示报表
    End If
Next
DataTables("MSDS").Save()

--  作者:有点蓝
--  发布时间:2019/6/29 11:35:00
--  
程序运行过程中肯定会属于假死状态。到Reports目录看看是不是有文件一直在输出?

我测试输出100个文档都可以的。

--  作者:xluoping
--  发布时间:2019/6/29 11:43:00
--  
昨晚上放了一个晚上就30个文件。怎么避免这种“假死”的情况

今天又试了,repors 里没有持续输出文件,只有30多个
[此贴子已经被作者于2019/6/29 11:44:01编辑过]

--  作者:有点蓝
--  发布时间:2019/6/29 11:52:00
--  
试试异步输出:http://www.foxtable.com/mobilehelp/scr/3269.htm

电脑会不会自动休眠?

--  作者:xluoping
--  发布时间:2019/6/29 14:52:00
--  
异步执行,但是发生了错误,以下代码是否正确?


全局变量:

Public tdr As Row


函数:msds

Dim tm As String  = ProjectPath & "Attachments\\MSDS.docx" \'指定模板文件
Dim st As String =  tdr("ICSC编号") & "-" & tdr("名称") & "-" & "国际化学品安全卡MSDS.docx"
st = st.Replace(" ","")
tdr("文件名") = st
If FileSys.FileExists(ProjectPath & "Reports\\"& st) = false then
    Dim fl As String = ProjectPath & "Reports\\"& st   \'指定目标文件
    Dim wrt As New WordReport(Tables("MSDS"),tm,fl) \'定义一个WordReport
    wrt.BuildOne(tdr)
    wrt.Replace("^13","^p")
    wrt.Quit() \'退出
End If

执行:

For Each tdr As Row In Tables("MSDS").Rows \'逐行生成报表
    Functions.AsyncExecute("msds")
Next
DataTables("MSDS").Save()

--  作者:有点蓝
--  发布时间:2019/6/29 15:56:00
--  
试试

函数:msds

dim t as table = args(0)
dim r as row = args(1)
dim tm as string = args(2)
dim fl as string = args(3)
Dim wrt As New WordReport(t,tm,fl) \'定义一个WordReport
    wrt.BuildOne(r)
    wrt.Replace("^13","^p")
    wrt.Quit() \'退出

执行:

Dim tm As String  = ProjectPath & "Attachments\\MSDS.docx" \'指定模板文件
For Each dr As Row In Tables("MSDS").Rows \'逐行生成报表
    Dim st As String =  dr("ICSC编号") & "-" & dr("名称") & "-" & "国际化学品安全卡MSDS.docx"
    st = st.Replace(" ","")
    dr("文件名") = st
    Dim fl As String = ProjectPath & "Reports\\"& st   \'指定目标文件
    If FileSys.FileExists(fl) = false then
        Functions.AsyncExecute("msds",Tables("MSDS"),dr,tm,fl)    
    End If
Next
DataTables("MSDS").Save()