poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yegor Kozlov <yegor.koz...@dinom.ru>
Subject Re: Workbook.setSheetHidden(int, bool) won't work for sheet (index == 0)
Date Tue, 24 Jan 2012 13:12:38 GMT
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
<Martin.Landl@fabasoft.com> 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: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Mime
View raw message