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) {
    }
  }

Reply via email to