0
我在64位Windows 7桌面工作站上的.Net Framework 4.5 Windows服務項目中使用Microsoft.Office.Interop.Excel,除了PageSetup屬性外,其他所有內容都可以正常工作更重要的是Worksheet對象的PrintOut方法。Microsoft.Office.Interop.Excel 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);
打印()錯誤:沒有安裝打印機。要安裝打印機,請單擊「文件」選項卡,然後單擊「打印」。單擊未安裝打印機,然後單擊添加打印機。按照添加打印機對話框中的說明進行操作。
我在我的設備和打印機中肯定有打印機。我有一個網絡打印機設置爲我的默認。我甚至將這臺打印機添加到Win.ini中,因爲我在其他帖子中看到過這種推薦,但無濟於事。
考慮到您必須將打印機設置爲默認值,因爲您沒有在PrintOut()調用中指定打印機。第五個參數:http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.worksheet.printout.aspx – gonxalo