c# Excel library

Printing Options(C#)

 
top
Setting Print Page

set print options for pages

//set landscape orientation
workBook.PrintLandscape = true;
//fit page
workBook.PrintScaleFitToPage = true;
//fitToWidth
workBook.PrintScaleFitHPages = 1;
//FitHeight
workBook.PrintScaleFitVPages = 2;
//set paper size
workBook.setPrintPaperSize(11906, 16838);//A4
//auto number
workBook.PrintAutoPageNumbering = true;

 
top
Setting Print Margins

set print options for margins

workBook.PrintLeftMargin = 0.7;
workBook.PrintTopMargin = 0.75;
workBook.PrintRightMargin = 0.7;
workBook.PrintBottomMargin = 0.75;
workBook.PrintHeaderMargin = 0.3;
workBook.PrintFooterMargin = 0.3;
workBook.PrintHCenter = true;
workBook.PrintVCenter = false;

Setting Print Header/Footer

set print options for headers/footers
MS Link(Formatting and VBA Codes for Headers and Footers)

workBook.PrintHeader = "&L&G";
workBook.PrintFooter = "&CPage &P of &N";

 
top
Setting Print Sheet.

set print options for sheet

workBook.PrintArea = "Sheet1!$A$1:$AG$787";
workBook.PrintTitles = "Sheet2!$M:$M,Sheet2!$11:$11";
workBook.PrintGridLines = false;
workBook.PrintNoColor = true;
workBook.PrintRowColHeading = true;

 
top
Setting Page Break.

set page/row/column break for printing

//add page break at B2
workBook.addRowPageBreak(2);
workBook.addColPageBreak(2);