【发布时间】: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