说明代码没有问题,应该是系统Excel进程不能及时注销,产生冲突引起的。
试试
Dim Book As New XLS.Book(ProjectPath & "Attachments\出库单.xls")
Dim fl As String = ProjectPath & "Reports\出库单.xls"
Book.Build()
Book.Save(fl)
Dim ps As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("excel")
For Each p As System.Diagnostics.Process In ps
If p.MainWindowTitle = Nothing Then p.kill
Next
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
ws.PrintOut
wb.Close
App.Quit