另一个更满意的方法
Dim Book As New XLS.Book(ProjectPath & "Attachments\订单.xls")
Dim file As String = ProjectPath & "Reports\订单.xls"
If FileIsOpened(file)= True Then '如果excel文件已打开
Shell("cmd.exe /c taskkill /f /im excel.exe") '强行关闭excel进程
MessageBox.Show("同名excel文件已打开,请按确认先关闭之,再重新打印!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Return '返回
End If
Book.Build() '生成细节区
Book.Save(file) '保存工作簿
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook
wb = App.WorkBooks.Open(file)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
With Ws.PageSetup
.PaperSize = MSExcel.XlPaperSize.xlPaperA4 '纸张大小
.CenterHorizontally = True '页面水平居中
.CenterVertically = True '页面垂直居中
.Zoom = False '以下设置将缩印在一页内
.FitToPagesWide = 1 '按照1页的宽度打印
.FitToPagesTall = 1 '按照1页的高度打印
End With
'App.Visible = True
Ws.PrintOut
wb.save
wb.close
App.Quit
[此贴子已经被作者于2014-1-4 0:08:18编辑过]