以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  直接打印问题求助  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=94945)

--  作者:llh0824
--  发布时间:2017/1/5 21:30:00
--  直接打印问题求助


图片点击可在新窗口打开查看此主题相关图片如下:打印错误.bmp
图片点击可在新窗口打开查看

代码如下,请问老师是什么问题

 

        Dim Book As New XLS.Book(ProjectPath & "Attachments\\打印单.xls")
        Dim fl As String = ProjectPath & "Reports\\打印单.xls"
        Book.Build()
        Book.Save(fl)
       
        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


--  作者:有点色
--  发布时间:2017/1/5 21:36:00
--  

直接执行这段,看是否报错

 

        Dim Book As New XLS.Book(ProjectPath & "Attachments\\打印单.xls")
        Dim fl As String = ProjectPath & "Reports\\打印单.xls"
        Book.Build()
        Book.Save(fl)


--  作者:llh0824
--  发布时间:2017/1/6 7:49:00
--  
直接运行这段没反应
--  作者:有点蓝
--  发布时间:2017/1/6 8:53:00
--  
说明代码没有问题,应该是系统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