设置打印机首选项 – 页面方向为横向

我想将Page orientation设置为LandScape,以便从我的excel Vsto项目中打印excel工作表。 手动页面方向是从“ 打印机首选项”窗口设置的,该窗口是从“打印”窗体弹出的。

我需要一些自动化,每次用户提供打印命令时,都会将方向设置为LandScape。

在此处输入图像描述

我注意到,如果我从我的Excel应用程序设置LandScape的方向,如果我想从MS-word应用程序给出打印,反之亦然。 因此必须有某种标志可以从任何简单的winform应用程序更改。

有什么方法可以操纵属性吗?

我找不到任何方法可以自定义任何单个打印机的打印机设置。 这是我为EXCEL应用程序工作的代码。

CommonData._WORKBOO K是一个静态工作簿对象

 Worksheet ws = CommonData._WORKBOOK.Application.ActiveSheet as Worksheet; var _with1 = ws.PageSetup; _with1.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape; CommonData._WORKBOOK.Application.Dialogs[Microsoft.Office.Interop.Excel.XlBuiltInDialog.xlDialogPrint].Show(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); 

您可以尝试以下类似的东西应该适合您

 public void CustPrinting() { try { strPrint = new StreamReader (filePath); try { printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); pd.PrinterSettings.PrinterName = printer; // Set the page orientation to landscape. pd.DefaultPageSettings.Landscape = true; pd.Print(); } finally { strPrint.Close() ; } } catch(Exception ex) { MessageBox.Show(ex.Message); } }