以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  word报表如何实现一次打印一份,自动打印?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=61619)

--  作者:xuezxz
--  发布时间:2014/12/16 10:09:00
--  word报表如何实现一次打印一份,自动打印?
请问打印多行数据时,如何只读取一行数据,生成文档后自动打印,再继续读取下一行,循环打印?
--  作者:有点甜
--  发布时间:2014/12/16 10:11:00
--  

 要用代码处理。

 

 http://www.foxtable.com/help/topics/2890.htm

 


--  作者:有点甜
--  发布时间:2014/12/16 10:12:00
--  

 打印word的代码

 

Dim app As New MSWord.Application
try
    Dim fileName = "e:\\test.doc"
    app.Documents.Open(fileName)
    \'app.Documents(fileName).PrintPreview
    \'app.Visible = True
    app.Documents(fileName).PrintOut \'打印
catch ex As exception
    msgbox(ex.message)
finally
    app.Quit
End try


--  作者:xuezxz
--  发布时间:2014/12/16 10:40:00
--  
甜甜同志,打印时会弹出提示,文件被锁定无法编辑,点确定后才行,能不能屏蔽掉这个提示呢?
--  作者:有点甜
--  发布时间:2014/12/16 10:42:00
--  

 弹出什么提示,我测试没问题。

 

Dim app As New MSWord.Application
try
    Dim fileName = "d:\\Test.doc"
    app.Documents.Open(fileName)
    \'app.Documents(fileName).PrintPreview
    \'app.Visible = True
    app.Documents(fileName).PrintOut \'打印
catch ex As exception
    msgbox(ex.message)
finally
    app.Quit
End try


--  作者:xuezxz
--  发布时间:2014/12/16 10:55:00
--  
图片点击可在新窗口打开查看


--  作者:xuezxz
--  发布时间:2014/12/16 10:57:00
--  
Dim flt As String
Dim tb As Table = e.Form.Controls("table1").Table
For Each xh As Row In Tb.Rows 
    Dim tm As String  = ProjectPath & "Attachments\\委托加工合同A.doc" \'指定模板文件
    Dim fl As String = ProjectPath & "Reports\\委托加工合同A.doc" \'指定目标文件
    Dim wrt As New WordReport(tb,tm,fl) \'定义一个WordReport
    wrt.Buildone(xh)
    Dim app As New MSWord.Application
    try
        \'  Dim fileName = "e:\\test.doc"
        app.Documents.Open(fl)
        \'app.Documents(fileName).PrintPreview
        \'app.Visible = True
        app.Documents(fl).PrintOut \'打印
    catch ex As exception
        msgbox(ex.message)
    finally
        app.Quit
    End try
Next
[此贴子已经被作者于2014-12-16 10:57:39编辑过]

--  作者:有点甜
--  发布时间:2014/12/16 10:57:00
--  

 生成报表的时候,不要执行 wrt.Show() \'显示报表

 

 然后,直接打印报表即可。


--  作者:xuezxz
--  发布时间:2014/12/16 12:27:00
--  
还是请老师帮忙检查下代码有没有问题吧,搞不定
Dim flt As String
Dim tb As Table = e.Form.Controls("table1").Table
For Each xh As Row In Tb.Rows
    If flt Is Nothing Then
        flt = "编号 = \'" & xh("编号") & "\'"
    Else
        flt = flt & " or 编号 = \'" & xh("编号") & "\'"
    End If
Next
If flt IsNot Nothing Then
    Dim jh As List(of DataRow) = DataTables("商品资料").Select(flt,"序号")
    If jh.Count > 0 Then
        Dim tm As String  = ProjectPath & "Attachments\\委托加工合同A.doc" \'指定模板文件
        Dim fl As String = ProjectPath & "Reports\\委托加工合同A.doc" \'指定目标文件
        Dim wrt As New WordReport(Tables("商品资料"),tm,fl) \'定义一个WordReport
        For Each dy As DataRow In jh
            wrt.Buildone(dy)
            Dim app As New MSWord.Application
            try
                \'Dim fileName = "e:\\test.doc"
                app.Documents.Open(fl)
                \'app.Documents(fileName).PrintPreview
                \'app.Visible = True
                app.Documents(fl).PrintOut \'打印
            catch ex As exception
                msgbox(ex.message)
            finally
                app.Quit
            End try
        Next
    End If
End If

问题1:会弹出上面发的图提示
问题2:表格中的数据无法读出,还是模板中设定的模样

--  作者:xuezxz
--  发布时间:2014/12/16 14:14:00
--  
顶一顶,有人在吗?