Dim e As Object = args(0)
Dim tb As Table = Tables(args(1))
Dim delfile As Boolean = True
Dim zdmc As String
Dim MyDate As Date = Functions.Execute("SQLTIME")
Select Case e.StripItem.Name
Case "打印","预览"
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 "房屋春检表"
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
fl = ProjectPath & "Attachments\报表模板\$$$临时文件.xls" '指定目标文件
If FileIsOpened(fl)= True Then
ShowAppWindow("$$$临时文件.xls",5) '关闭打开的文件
End If
Dim App As MSExcel.Application
Dim Wb As MSExcel.WorkBook
Dim Ws As MSExcel.WorkSheet
Dim Book As New XLS.Book(tm)
try
'对标记进行更新
Book.Marks.Add("tihuan单位简称",sz(1))
Book.Marks.Add("tihuan所属车间",sz(3))
Book.Marks.Add("tihuan所属工区",sz(5))
Book.Marks.Add("tihuandayingren",_UserName)
Book.Marks.Add("tihuandayingshijian",Format(Functions.Execute("SQLTIME"),"yyyy年MM月dd日"))
Book.Build() '生成报表
Book.Save(fl) '保存工作簿
ShowAppWindow("$$$临时文件.xls",5) '关闭打开的文件
MessageBox.Show(45)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim tpcs() As String '图片参数
Dim file As String
Dim img As image
MessageBox.Show(451)
app = New MSExcel.Application
MessageBox.Show(452) '此消息框弹出后再关闭 '执行到这儿出错?????????????????????????????????????????????????????????????????????????????
wb = app.WorkBooks.Open(fl)
MessageBox.Show(453)
ws = wb.WorkSheets(1)
MessageBox.Show(46)
MessageBox.Show(47)
app.DisplayAlerts = False '每次出现需用户应答的消息时,Microsoft Excel将选择默认应答
wb.saved = True
app.visible = True
MessageBox.Show(48)
ShowAppWindow("$$$临时文件.xls",2) '查找指定标题的外部应用程序窗口,并显示?隐藏或关闭之. 2-最大化显示
If e.StripItem.Name = "预览" Then
MessageBox.Show(49)
Ws.PrintPreview
MessageBox.Show(491)
Else
MessageBox.Show(50)
Ws.PrintOUT
MessageBox.Show(51)
End If
catch ex As exception
MessageBox.Show(ex.message,"提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
finally
App.Quit
End try
MessageBox.Show(98)
End If
'----------------------------------------------------------------------------------------------------
'删除临时文件
Do While True
If delfile = True Then
If FileSys.FileExists(fl) Then
try
io.File.delete(fl)
catch ex As exception
application.Doevents
End try
Else
Exit Do
End If
End If
Loop
End Select
'****************************************************************************************************