Excel自动化:PDF导出导致“打印机设置”弹出 [英] Excel automation: PDF export causes "Printer setup" popup

查看:1617
本文介绍了Excel自动化:PDF导出导致“打印机设置”弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发自动Excel到PDF生成的应用程序。每一次(无任何明显的原因)程序运行时出现以下弹出窗口:


打印32位应用程序的驱动程序主机已停止工作。




,不久之后,这一个:


打印机设置




如果有什么,我需要做什么我的应用程序不是太复杂,总是(100%)的错误发生在这一行上:

  _application.ActiveWorkbook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF,
pdfTemplatePath,Excel.XlFixedFormatQuality。 xlQualityStandard,
_,_,1,pdfPrintAreaEnd);

  Excel:= Microsoft.Office.Intertop.Excel 
_application:= Excel.Application
_:= System.Type.Missing
pdfPrintAreaEnd:= int 6

异常消息如下:

  System.Runtime.InteropServices.COMException(0x800A03EC):
HRESULT异常:0x800A03EC
/ pre>

这里发生了什么?而且,更重要的是:为什么只会在一段时间内发生?

解决方案

,我遇到了我认为是关于Excel自动化的令人困惑的事情之一到目前为止遇到过。



错误信息与Excel使用的其他情况一致,这两种情况都是自动的,而不是自动化。所有这些情况下的共同点是(扣上!),网络打印机被设置为默认打印机。



没错网络打印机是默认的,即使使用完全不同的打印机或根本没有打印机进行打印(如在导出为PDF的情况下,与打印到Adobe PDF打印机不一样,是否正确?)会导致此错误有时在某些机器上弹出



我将默认打印机更改为内部的一些内容,如 Microsoft XPS文档打印机,再试一次,我现在可以导出数以千计的PDF,而不会出现错误信息。


I am developing an application for automatic Excel to PDF generation. Every now and then (and without any apparent cause, the following popup comes up while the program runs:

Print driver host for 32bit applications stopped working.

and, shortly after, this one:

Printer setup

What, if anything, do I need to do here? My application is not overly complex. The error always (100%) happens on this line:

_application.ActiveWorkbook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF,
    pdfTemplatePath, Excel.XlFixedFormatQuality.xlQualityStandard, 
    _, _, 1, pdfPrintAreaEnd);

where the variables in question are:

Excel := Microsoft.Office.Intertop.Excel
_application := Excel.Application
_ := System.Type.Missing
pdfPrintAreaEnd := int 6

The exception message is as follows:

System.Runtime.InteropServices.COMException (0x800A03EC):
    Exception from HRESULT: 0x800A03EC

What is happening here? And, more importantly: Why is it only happening every one in a while?

解决方案

Okay, so after some research into this matter, I encountered what I believe is one of the most confuzzling things about Excel automation I have encountered so far.

The error message is consistent with other cases of Excel usage that are both automated and not. The common denominator in all these cases is (buckle up!) that a network printer was set as default printer.

That's right - having a network printer as default, even when you print using a completely different printer or no printer at all (as in the case of exporting to PDF, which is not the same as printing to e.g. Adobe PDF Printer, right?) it will cause this error to sometimes on some machines pop up.

I changed the default printer to something internal, like Microsoft XPS Document Printer, tried again and I can now export hundreds and thousands of PDFs without a single occurrence of the error message.

这篇关于Excel自动化:PDF导出导致“打印机设置”弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆