Dim e As RequestEventArgs = rq.e
Dim cmd As SQLCommand = rq.cmd
Dim tm As String = ProjectPath & "Attachments\" & e.Values("文书名") & ".doc" '指定模板文件
If FileSys.FileExists(tm) Then
Try
Dim time As String = Format(Date.now, "yyyyMMddHHmmssfffff")
Dim f1 As String = ProjectPath & "mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & ".doc" '指定目标文件
Dim f2 As String = ProjectPath & "mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & ".pdf" '指定目标PDF文件
Dim wrt As New WordReport(tm, f1)
wrt.AddDataTable(e.Values("文书名"), "主数据源", "Se lect * from {" & e.Values("文书名") & "} where guid = '" & e.Values("guid") & "' ")
cmd.CommandText = "sel ect * from SYS_Dictionary where 字典值='是' and 分类='PDF预览'"
Dim dt As DataTable = cmd.ExecuteReader()
If dt.DataRows.Count > 0 Then
wrt.Build()
wrt.SaveToPDF(f2) '保存为PDF文件
wrt.Quit() '退出
e.WriteString("\mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & ".pdf")
Else
wrt.Build()
'wrt.Show()
wrt.Quit() '退出
e.WriteString("\mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & ".doc")
End If
Catch ex As Exception
Dim time As String = Format(Date.now, "yyyyMMddHHmmssfffff")
Dim f1 As String = ProjectPath & "mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & ".doc" '指定目标文件
Dim f2 As String = ProjectPath & "mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & ".pdf" '指定目标PDF文件
Dim wrt As New WordReport(tm, f1)
wrt.AddDataTable(e.Values("文书名"), "主数据源", "S elect * from {" & e.Values("文书名") & "} where guid = '" & e.Values("guid") & "' ")
cmd.CommandText = "sel ect * from SYS_Dictionary where 字典值='是' and 分类='PDF预览'"
Dim dt As DataTable = cmd.ExecuteReader()
If dt.DataRows.Count > 0 Then
wrt.Build()
wrt.SaveToPDF(f2) '保存为PDF文件
wrt.Quit() '退出
e.WriteString("\mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & ".pdf")
Else
wrt.Build()
'wrt.Show()
wrt.Quit() '退出
e.WriteString("\mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & ".doc")
End If
End Try
Else
e.WriteString(e.Values("文书名") & "[文件不存在或已经被删除!]")
End If