2016-12-08 110 views
1

我的程序將在同一個EXCEL文件中導出WorkSheets。我正在嘗試將打印默認設置設置爲「打印整個工作簿」。我嘗試使用PrintOutEx進行設置,但是當我導出EXCEL時,它會立即打印出worksheets或進入預覽模式。如何設置EXCEL打印設置「打印整個工作表」? C#

我只是想將默認設置爲Print Entire Workbook。我想讓用戶先閱讀excel文件。怎麼辦?謝謝。

這裏是我的代碼:

Excel.Application oApp; 
       Excel.Worksheet oSheet; 
       Excel.Workbook oBook; 

       //Check if the row records are more then the table row. 
       if (rowCount > 19) 
        more_than_table = true; 

       oApp = new Excel.Application(); 
       oBook = oApp.Workbooks.Add(); 

       do { 
        Debug.WriteLine("Page: " + sheet_page); 

       oSheet = (Excel.Worksheet)oBook.Worksheets.Add(After: oBook.Sheets[oBook.Sheets.Count]); 

       oSheet.Name = invoices_tb.Text + "(" + sheet_page + ")"; 
       oApp.Application.UserName = invoices_tb.Text; 
       oApp.Visible = true; 
       //Set up the excel page style, orientation and the center alignment 
       //oSheet.PageSetup.Zoom = false; 
       oSheet.PageSetup.Zoom = false; 
       oSheet.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape; 
       oSheet.PageSetup.CenterHorizontally = true; 
       oSheet.PageSetup.FitToPagesWide = 1; 

       //Set the page number 
       oSheet.PageSetup.CenterFooter = "Page &P of &N"; 

       //** 
       //Many code for set up excel and value 
       //** 

        double how_many_page = Convert.ToDouble(rowCount)/19.0f ; 
        Debug.WriteLine("many page: " + how_many_page); 
        if (how_many_page > sheet_page) 
         sheet_page++; 
        else 
         more_than_table = false; 

       } while (more_than_table); 

       //Set to preview the page when file export. 
       oBook.PrintOutEx(1, sheet_page, 1, true, Type.Missing, true, false, Type.Missing); 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show("Excel Closed."); 
      } 

回答

0

使用這條線使用C#打印整個工作簿...

excelWorkbook.PrintOut(預覽:真,分頁:真);