这样写是哪个地方有问题,提示“目标报表文件已经被其他进程打开,生成的报表将存为一个临时文件”,然后打印出来的都是第一个文件
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