以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 打印报错 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=119950) |
-- 作者:qaz17909 -- 发布时间:2018/6/4 17:54:00 -- 打印报错 点击控件后打印复选框中的勾选的行,第一次可以,但是第二次点击的时候报错,“报告.doc已被锁定,无法编制” Dim rs As List(of Row) = t.GetCheckedRows If rs.Count > 0 Then \'如果存在符合条件的行 Dim tm As String = ProjectPath & "Attachments\\报告.doc" \'指定模板文件 Dim fl As String = ProjectPath & "Reports\\报告.doc" Dim wrt As New WordReport(Tables("报告_Table1"),tm,fl) \'定义一个WordReport For Each r As Row In rs \'逐行生成报表 wrt.BuildOne(r) wrt.RecordsOnEachPage = 1 Next \'wrt.Show() \'显示报表 Dim Proc As New Process \'打开工作簿 Proc.File = fl Proc.Verb= "Print" Proc.Start() Else MessageBox.show("请先勾选要打印的报告!") End If |
-- 作者:有点甜 -- 发布时间:2018/6/4 18:26:00 -- 打印word报表这样写代码,参考
Dim app As New MSWord.Application |
-- 作者:qaz17909 -- 发布时间:2018/6/4 20:52:00 -- 这样写对吗,好像“报告.doc”文件未保存仍然占用,所以无法打印。 Dim rs As List(of Row) = t.GetCheckedRows If rs.Count > 0 Then \'如果存在符合条件的行 Dim tm As String = ProjectPath & "Attachments\\报告.doc" \'指定模板文件 Dim fl As String = ProjectPath & "Reports\\报告.doc" Dim wrt As New WordReport(Tables("报告_Table1"),tm,fl) \'定义一个WordReport For Each r As Row In rs \'逐行生成报表 wrt.BuildOne(r) wrt.RecordsOnEachPage = 1 Next \'wrt.Show() \'显示报表 Dim app As New MSWord.Application try Dim doc = app.Documents.Open(fl) Doc.PrintPreview app.Visible = True Doc.PrintOut \'打印 catch ex As exception msgbox(ex.message) finally app.Quit End try Else MessageBox.show("请先勾选要打印的报告!") End If |
-- 作者:有点蓝 -- 发布时间:2018/6/4 21:03:00 -- Dim rs As List(of Row) = t.GetCheckedRows If rs.Count > 0 Then \'如果存在符合条件的行 Dim tm As String = ProjectPath & "Attachments\\报告.doc" \'指定模板文件 Dim fl As String = ProjectPath & "Reports\\报告.doc" Dim wrt As New WordReport(Tables("报告_Table1"),tm,fl) \'定义一个WordReport For Each r As Row In rs \'逐行生成报表 wrt.BuildOne(r) wrt.RecordsOnEachPage = 1 Next wrt.Quit \'wrt.Show() \'显示报表 Dim app As New MSWord.Application try Dim doc = app.Documents.Open(fl) Doc.PrintPreview app.Visible = True Doc.PrintOut \'打印 catch ex As exception msgbox(ex.message) finally app.Quit End try Else MessageBox.show("请先勾选要打印的报告!") End If
|
-- 作者:qaz17909 -- 发布时间:2018/6/5 8:13:00 -- 这样写是哪个地方有问题,提示“目标报表文件已经被其他进程打开,生成的报表将存为一个临时文件”,然后打印出来的都是第一个文件 Dim rs As List(of Row) = t.GetCheckedRows If rs.Count > 0 Then \'如果存在符合条件的行 For Each r As Row In rs \'逐行生成报表 If r("送样方式") = "自送样" Then Dim tm As String = ProjectPath & "Attachments\\自送样报告首页.doc" \'指定模板文件 Dim fl As String = ProjectPath & "Reports\\自送样报告首页.doc" Dim wrt As New WordReport(Tables("报告打印_Table1"),tm,fl) \'定义一个WordReport wrt.BuildOne(r) wrt.RecordsOnEachPage = 1 wrt.Quit Dim app As New MSWord.Application try Dim doc = app.Documents.Open(fl) Doc.PrintPreview app.Visible = True Doc.PrintOut \'打印 catch ex As exception msgbox(ex.message) finally app.Quit End try Else If r("送样方式") = "自采样" Then Dim tm As String = ProjectPath & "Attachments\\自采样报告首页.doc" \'指定模板文件 Dim fl As String = ProjectPath & "Reports\\自采样报告首页.doc" Dim wrt As New WordReport(Tables("报告打印_Table1"),tm,fl) \'定义一个WordReport wrt.BuildOne(r) wrt.RecordsOnEachPage = 1 wrt.Quit Dim app As New MSWord.Application try Dim doc = app.Documents.Open(fl) Doc.PrintPreview app.Visible = True Doc.PrintOut \'打印 catch ex As exception msgbox(ex.message) finally app.Quit End try End If Next Else MessageBox.show("请先勾选要打印的报告!") End If |
-- 作者:有点甜 -- 发布时间:2018/6/5 8:45:00 -- 比如
Dim tm As String = ProjectPath & "Attachments\\自送样报告首页.doc" \'指定模板文件
Dim fl As String = ProjectPath & "Reports\\自送样报告首页.doc"
Dim wrt As New WordReport(Tables("报告打印_Table1"),tm,fl) \'定义一个WordReport
wrt.BuildOne(r)
wrt.RecordsOnEachPage = 1
wrt.Quit
Dim app As New MSWord.Application
try
Dim doc = app.Documents.Open(fl)
\'Doc.PrintPreview
\'app.Visible = True
Doc.PrintOut \'打印
catch ex As exception
msgbox(ex.message)
finally
app.Quit
End try
|
-- 作者:qaz17909 -- 发布时间:2018/6/5 8:57:00 -- 没有改变,还是出现一样的情况 |
-- 作者:有点甜 -- 发布时间:2018/6/5 9:48:00 -- Dim fl As String = ProjectPath & "Reports\\自送样报告首页.doc"
改成
Dim fl As String = ProjectPath & "Reports\\自送样报告首页" & r("_Identify") & ".doc" |
-- 作者:qaz17909 -- 发布时间:2018/6/5 10:47:00 -- 可以了,谢谢! |