【问题标题】:Microsoft.Office.Interop.Excel PrintOut Throws ErrorMicrosoft.Office.Interop.Excel 打印输出引发错误
【发布时间】:2014-05-06 20:07:45
【问题描述】:

我在我的 64 位 Windows 7 桌面工作站上的 .Net Framework 4.5 Windows 服务项目中使用 Microsoft.Office.Interop.Excel,除了 PageSetup 属性,更重要的是 Worksheet 对象的 PrintOut 方法外,一切似乎都在工作.

代码如下:

Microsoft.Office.Interop.Excel.Application ExcelApp = null;
Microsoft.Office.Interop.Excel.Workbook WBook = new Microsoft.Office.Interop.Excel.Workbook;
Microsoft.Office.Interop.Excel.Worksheet WSheet = new Microsoft.Office.Interop.Excel.Worksheet);

ExcelApp = new Microsoft.Office.Interop.Excel.Application();

WBook = ExcelApp.Workbooks.Add();

WSheet = WBook.Worksheets[1];

//Do some stuff with the sheet

//None of this works, throws an error: Unable to set the Orientation property of the PageSetup class
WSheet.PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;
WSheet.PageSetup.Zoom = false;
WSheet.PageSetup.FitToPagesWide = 1;
WSheet.PageSetup.FitToPagesTall = false;

//Throws Error (see below)
WSheet.PrintOut(null, null, null, null, null, null, null);

PrintOut() 错误: 没有安装打印机。要安装打印机,请单击文件选项卡,然后单击打印。单击未安装打印机,然后单击添加打印机。按照“添加打印机”对话框中的说明进行操作。

我的设备和打印机中确实定义了打印机。我有一个网络打印机设置为我的默认值。我什至已将此打印机添加到 Win.ini,因为我在其他帖子中看到过此建议,但无济于事。

【问题讨论】:

    标签: c# windows-services excel-interop


    【解决方案1】:

    我在写这个问题时发现了这一点。

    确保您在已设置打印机和指定默认打印机的帐户下运行 Windows 服务。我在本地服务帐户下运行该服务,一旦我将其切换为在我的个人帐户下运行,PageSetup 属性和 PrintOut() 方法都有效!

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多