See what happens:

 if (i == 0) {
       wb.setSheetHidden(0, true); // won't hide the sheet!
       // wb.setSheetHidden(0, Workbook.SHEET_STATE_VERY_HIDDEN); will
hide the sheet
}

at this point the workbook contains one sheet and you are trying to
hide it. At any state at least one sheet should be visible.

Move the hiding logic outside of the loop.

Yegor


On Tue, Jan 24, 2012 at 2:41 PM, Landl, Martin
<[email protected]> wrote:
> Hello!
>
> I'm using Workbook.setSheetHidden(int, boolean) to hide several sheets within 
> a Workbook.
> This works for all sheets, except for the FIRST sheet (index == 0). The sheet 
> won't hide.
>
> I can only get the sheet (index 0) to hide, by using 
> Workbook.setSheetHidden(0, Workbook.SHEET_STATE_VERY_HIDDEN), which is not 
> what I want to do.
>
> Is there something missing (like selecting another tab than the first) ?
>
> Regards,
> Martin
>
>
>  public static void main(String[] args)
>  {
>    Workbook wb = new XSSFWorkbook();
>
>    for (int i = 0; i < 6; i++) {
>      String newSheetName = WorkbookUtil.createSafeSheetName("Sheet " + i);
>      wb.createSheet(newSheetName);
>
>      if (i == 0) {
>        wb.setSheetHidden(0, true); // won't hide the sheet!
>        // wb.setSheetHidden(0, Workbook.SHEET_STATE_VERY_HIDDEN); will hide 
> the sheet
>      }
>      if (i == 3) {
>        wb.setSheetHidden(3, true);
>      }
>      if (i == 5) {
>        wb.setSheetHidden(5, true);
>      }
>
>      // expected:
>      // Sheet 1
>      // Sheet 2
>      // Sheet 4
>
>      // got:
>      // Sheet 0 <-- should be invisible, but is visible and selected
>      // Sheet 1
>      // Sheet 2
>      // Sheet 4
>
>    }
>
>    try {
>      File tempFile = File.createTempFile("workbook", ".xlsx");
>      System.out.println("output=" + tempFile.getAbsolutePath());
>      FileOutputStream outputFile = new FileOutputStream(tempFile);
>      wb.write(outputFile);
>    }
>    catch (FileNotFoundException e) {
>    }
>    catch (IOException e) {
>    }
>  }

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to