]> source.dussan.org Git - poi.git/commitdiff
bug 60605: remove code for enforcing rule that active sheet cannot be hidden
authorJaven O'Neal <onealj@apache.org>
Fri, 20 Jan 2017 04:55:06 +0000 (04:55 +0000)
committerJaven O'Neal <onealj@apache.org>
Fri, 20 Jan 2017 04:55:06 +0000 (04:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1779561 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
src/java/org/apache/poi/ss/util/WorkbookUtil.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetHiding.java

index e8be284f19c7bcb6a0cc91f1808966b4399ab73a..878abd33e52bf86184ef9f70b2f830eda26c2971 100644 (file)
@@ -783,11 +783,6 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
     @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);
     }
 
index f5e5f40fe8ccc548d68fdd2dbe3c8e9f69154b76..d08edcac547b346518e5b7448dafd35671e271cb 100644 (file)
@@ -185,33 +185,4 @@ public class WorkbookUtil {
                             "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;
-        }
-    }
 }
index a64681222fe718b22b95963c8e9c89de8a0b059c..7942ff339740011ccbc21972baaece3e3323fa20 100644 (file)
@@ -1992,10 +1992,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
     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:
index 5a35b3b4b5dea937bce90a03631fd6183ba89f42..46117a062496c575b54f48ddad6fe879663993ba 100644 (file)
@@ -130,32 +130,6 @@ public abstract class BaseTestSheetHiding {
     
         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,