Setting Printer Preference - Page Orientation to Landscape

前端 未结 2 1305
时光取名叫无心
时光取名叫无心 2021-01-21 06:53

I would like to set the Page orientation to LandScape for printing excel worksheet from my excel Vsto project. Manually page orientation is set from the Printer Preferen

相关标签:
2条回答
  • 2021-01-21 07:45

    You can try something like the following below should work for you

    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);
       }
     }
    
    0 讨论(0)
  • 2021-01-21 07:53

    I could not find any way we could customize the printer settings of any individual printer. Here's the code which worked for me for EXCEL application.

    CommonData._WORKBOOK is a static workbook object

    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);
    
    0 讨论(0)
提交回复
热议问题