I have dug some more, and now I think the issue is related to paper size.  
Steps:
1. Create a workbook from POI
2. Add three sheets,
3. Fill each sheet with some data
4. Set paper size to A4
5. Write to file

Now open the file in Excel (I have Excel 2003 running on XP). Send the
workbook to printer with Entire Workbook option selected. Only the first
worksheet gets printed although the print status shows 3 pages were sent to
printer.

The bug can be reproduced with following simple code:

    public static void main(String args[]) {
        HSSFWorkbook wb = new HSSFWorkbook();
        //Create 3 sheets with some numeric data and set paper size to A4
        for (int i = 0; i < 3; i++) {
            HSSFSheet sheet = wb.createSheet();
            fill(sheet);
            sheet.getPrintSetup().setPaperSize((short) 9); //A4
        }
        //Write to file
        try {
            FileOutputStream fileOut = new
FileOutputStream("threesheets-a4.xls");
            wb.write(fileOut);
            fileOut.close();
        } catch (Exception e) {
            System.out.println(e);
        }

    }

    private static void fill(HSSFSheet sheet) {
        for (int i = 0; i < 10; i++) {
            HSSFRow row = sheet.createRow(i);
            for (int c = 0; c < 5; c++) {
                HSSFCell cell = row.createCell((short) c);
                cell.setCellValue(c);
            }
        }
    }

Regards,
Tahir Akhtar
> -----Original Message-----
> From: Tahir Akhtar [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, June 13, 2007 4:58 PM
> To: 'POI Users List'
> Subject: RE: Can't print entire workbook
> 
> > From: Nick Burch
> > Sent: Wednesday, June 13, 2007 4:49 PM
> >
> > On Wed, 13 Jun 2007, Tahir Akhtar wrote:
> > > Interestingly if I create a workbook directly in excel and set all
> > > sheets as selected by ctrl-clicking on sheet name, all sheets print
> > > fine.
> >
> > One thing to try is:
> > * produce a workbook with no sheets selected
> > * load it in poi, select all the sheets, and write it out to one file
> > * load it in excel, select all the sheets, and write out to another file
> >
> > Then use the tools under org.apache.poi.hssf.dev to see if there are any
> > obvious differences between the two. (It could well be that there's
> > another set of record we need to be changed for selection that we don't
> > release need altering)
> Thanks for the suggestion. I have never used the dev tools so any pointers
> will be helpful.
> One more interesting fact about this case is that when print starts, print
> status dialog shows all pages going to print. For example if there are 10
> sheets with one page content, the print status dialog would say "Sending
> 10
> pages to printer".
> 
> >
> > Nick
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to