Not sure about HSSF as I don't use it for output but in XSSF doing the below 
gets me "fit all columns on one page":

XSSFPrintSetup ps = (XSSFPrintSetup) sheet.getPrintSetup();
sheet.setAutobreaks(true);
sheet.setFitToPage(true);
ps.setFitWidth((short)1);
ps.setFitHeight(0);


Don't call setFitHeight with a non-zero value as that will make Excel try to 
fit all the sheets rows on however many pages you set (you may be able to get 
away with not calling it at all). Setting the print area on the sheet may help 
as well:

workbook.setPrintArea(sheetIndex, 0, nColumns, 0, nRows);


Regards
Darren




>________________________________
> From: Raj Konds <[email protected]>
>To: [email protected] 
>Sent: Thursday, August 8, 2013 7:17 AM
>Subject: Fwd: Need to setup Print option "Fit All Columns on One Page" in poi 
>java code
> 
>
>Please provide some assistance asap.
>Thanks.
>
>
>---------- Forwarded message ----------
>From: Raj Konds <[email protected]>
>Date: Wed, Aug 7, 2013 at 4:16 PM
>Subject: Need to setup Print option "Fit All Columns on One Page" in poi
>java code
>To: [email protected], [email protected]
>
>
>Hi all,
>
>I know that following poi code will setup the print option "Fit Sheet on
>One Page" by default
>
>    Workbook wb = new HSSFWorkbook();
>    Sheet sheet = wb.createSheet("format sheet");
>    PrintSetup ps = sheet.getPrintSetup();
>
>    sheet.setAutobreaks(true);
>
>    ps.setFitHeight((short)1);
>    ps.setFitWidth((short)1);
>
>
>But my requirement is to setup Print Option "Fit All Columns on One
>Page" by default. i.e. when the excel is generated and user presses
>Ctrl+P it should show the Print dialog box with "Fit All Columns on
>One Page" option by default.
>
>I tried with
>
>    ps.setFitHeight((short)2);
>    ps.setFitWidth((short)2);
>
>but it doesn't work.
>
>Can somebody please help asap, need help urgently.
>
>Thanks,
>
>Rajesh
>
>
>

Reply via email to