@Override
public void setSheetVisibility(int sheetIx, SheetVisibility visibility) {
validateSheetIndex(sheetIx);
-
- /*if (visibility != SheetVisibility.VISIBLE && sheetIx == getActiveSheetIndex()) {
- throw new IllegalStateException("Cannot hide the active sheet. Change active sheet before hiding.");
- }*/
-
workbook.setSheetHidden(sheetIx, visibility);
}
"Sheet state must be one of the Workbook.SHEET_STATE_* constants");
}
}
-
- @Internal(since="3.16 beta 2")
- public static int getNextActiveSheetDueToSheetHiding(Workbook wb, int sheetIx) {
- if (sheetIx == wb.getActiveSheetIndex()) {
- // activate next sheet
- // if last sheet in workbook, the previous visible sheet should be activated
- final int count = wb.getNumberOfSheets();
- for (int i=sheetIx+1; i < count; i++) {
- // get the next visible sheet in this workbook
- if (SheetVisibility.VISIBLE == wb.getSheetVisibility(i)) {
- return i;
- }
- }
-
- // if there are no sheets to the right or all sheets to the right are hidden, activate a sheet to the left
- for (int i=sheetIx-1; i < count; i--) {
- if (SheetVisibility.VISIBLE == wb.getSheetVisibility(i)) {
- return i;
- }
- }
-
- // there are no other visible sheets in this workbook
- return -1;
- //throw new IllegalStateException("Cannot hide sheet " + sheetIx + ". Workbook must contain at least 1 other visible sheet.");
- }
- else {
- return sheetIx;
- }
- }
}
public void setSheetVisibility(int sheetIx, SheetVisibility visibility) {
validateSheetIndex(sheetIx);
- /*if (visibility != SheetVisibility.VISIBLE && sheetIx == getActiveSheetIndex()) {
- throw new IllegalStateException("Cannot hide the active sheet. Change active sheet before hiding.");
- }*/
-
final CTSheet ctSheet = sheets.get(sheetIx).sheet;
switch (visibility) {
case VISIBLE:
wb.close();
}
-
- @Ignore
- @Test
- public void testCannotHideActiveSheet() throws IOException {
- Workbook wb = _testDataProvider.createWorkbook();
- wb.createSheet("Active Sheet");
- wb.createSheet("Inactive Sheet");
- wb.setActiveSheet(0);
- assertEquals(0, wb.getActiveSheetIndex());
-
- try {
- wb.setSheetVisibility(0, SheetVisibility.VERY_HIDDEN);
- fail("Should not be able to hide an active sheet");
- } catch (final IllegalStateException e) {
- // expected
- }
-
- try {
- wb.setSheetVisibility(0, SheetVisibility.HIDDEN);
- fail("Should not be able to hide an active sheet");
- } catch (final IllegalStateException e) {
- // expected
- }
-
- wb.close();
- }
/**
* Test that we get the right number of sheets,