Printing Options(Java)

 
top
Setting Print Page

set print options for pages

//set landscape orientation
workBook.setPrintLandscape(true);
//fit page
workBook.setPrintScaleFitToPage(true);
//fitToWidth
workBook.setPrintScaleFitHPages(1);
//FitHeight
workBook.setPrintScaleFitVPages(2);
//set paper size
workBook.setPrintPaperSize(11906, 16838);//A4
//auto number
workBook.setPrintAutoPageNumbering(true);

 
top
Setting Print Margins

set print options for margins

workBook.setPrintLeftMargin(0.7);
workBook.setPrintTopMargin(0.75);
workBook.setPrintRightMargin(0.7);
workBook.setPrintBottomMargin(0.75);
workBook.setPrintHeaderMargin(0.3);
workBook.setPrintFooterMargin(0.3);
workBook.setPrintHCenter(true);
workBook.setPrintVCenter(false);

Setting Print Header/Footer

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

workBook.setPrintHeader("&L&G");
workBook.setPrintFooter("&CPage &P of &N");

 
top
Setting Print Sheet.

set print options for sheet

workBook.setPrintArea("Sheet1!$A$1:$AG$787");
workBook.setPrintTitles("Sheet2!$M:$M,Sheet2!$11:$11");
workBook.setPrintGridLines(false);
workBook.setPrintNoColor(true);
workBook.setPrintRowColHeading(true);

 
top
Setting Page Break.

set page/row/column break for printing

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