Dim tp As Boolean = False Dim dpi = basemainform.CreateGraphics.dpiX
Dim sz() As String
If tb.Cols.Contains("部门编号") = True Then
sz = Functions.Execute("dwcjgq",tb.Current("部门编号")).split("|")
End If
Dim mb,str,tm,fl As String
If tb.Cols.Contains("审核人") = True AndAlso tb.Current("审核人").trim(" ") <> "" Then
mb = "_已审核"
End If
'----------------------------------------------------------------------------------------------------
'选择模板
Select Case tb.name
Case "请修任务"
tm = ProjectPath & "Attachments\报表模板\请修派工单模板.xls"
Case "房屋台账"
str = ProjectPath & "Attachments\报表模板\房屋台账模板.doc"
tm = str.SubString(0,str.Length-4) & mb & str.SubString(str.Length-4,4) '指定模板文件
Case "房屋春检表"
str = ProjectPath & "Attachments\报表模板\房屋春检调查表模板.xls"
tm = str.SubString(0,str.Length-4) & mb & str.SubString(str.Length-4,4) '指定模板文件
Case "公建春检表"
str = ProjectPath & "Attachments\报表模板\公建春检调查表模板.xls"
tm = str.SubString(0,str.Length-4) & mb & str.SubString(str.Length-4,4) '指定模板文件
End Select
If FileSys.FileExists(tm) = False Then
Messagebox.Show("报表模板文件【" & tm & "】不存在 !" & vblf & "请联系系统超级管理员 !","提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End If
'----------------------------------------------------------------------------------------------------
'根据不同类型的模板,选择不同的程序段
If tm.EndsWith(".xls") Then
ElseIf tm.EndsWith(".doc") Then
fl = ProjectPath & "Attachments\报表模板\$$$临时文件.doc" '指定目标文件
If FileIsOpened(fl)= True Then
ShowAppWindow("$$$临时文件.doc",5) '关闭打开的文件
End If
Dim app As MSWord.Application
' Dim Doc As Documents
Dim wrt As New WordReport(tb,tm,fl) '定义一个WordReport
try
wrt.replace("tihuan单位简称",sz(1))
wrt.replace("tihuan所属车间",sz(3))
wrt.replace("tihuan所属工区",sz(5))
wrt.replace("tihuan打印人",_UserTag)
wrt.replace("tihuan打印时间",Format(MyDate,"yyyy年MM月dd日"))
Select Case tb.name
Case "房屋台账"
Dim file As String = ProjectPath & "RemoteFiles\" & tb.Current("照片")
Dim img As image = getImage(file)
Dim ZPwidth As Integer = img.width '照片原始宽度 像素
Dim ZPheight As Integer = img.height '照片原始高度 像素
Dim Docwidth As Integer = 324-4 '324磅=432像素 '模板照片框宽度 磅 1像素 = 3/4磅
Dim Docheight As Integer = 256-10 '256磅=336像素6 '模板照片框高度 磅 1像素 = 3/4磅
Dim bl,Wbl,Hbl As Double '原始图片像素和模板照片框比例
Wbl = ZPwidth/Docwidth
Hbl = ZPheight/Docheight
Dim width,height As Integer
If ZPwidth <= Docwidth AndAlso ZPheight <= Docheight Then
width = ZPwidth
height = ZPheight
ElseIf ZPwidth > Docwidth AndAlso ZPheight <= Docheight Then
width = ZPwidth
height = Cint(ZPheight/Wbl)
ElseIf ZPwidth <= Docwidth AndAlso ZPheight > Docheight Then
width = Cint(ZPwidth/Hbl)
height = Docheight
ElseIf ZPwidth > Docwidth AndAlso ZPheight > Docheight Then
If Wbl >= Hbl Then
width = Cint(ZPwidth/Wbl)
height = Cint(ZPheight/Wbl)
Else
width = Cint(ZPwidth/Hbl)
height = Cint(ZPheight/Hbl)
End If
End If
wrt.ReplaceWithImage("Tihuan照片",file, width, height)
End Select
If tb.Current("审核人").trim(" ") <> "" Then
wrt.replace("未审核.png","已审核.png")
End If
wrt.Build() '逐行生成报表
wrt.Quit() '退出
app = New MSWord.Application
Dim Doc = app.Documents.Open(fl)
app.DisplayAlerts = False
Doc.saved = True
app.visible = True
ShowAppWindow("$$$临时文件.doc",2)
If e.StripItem.Name = "预览" Then
Doc.PrintPreview
Else
Doc.printout
End If
catch ex As exception
MessageBox.Show(ex.message,"提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
finally
App.Quit
End try
End If