poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r693175 - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/hssf/model/ java/org/apache/poi/hssf/record/ java/org/apache/poi/hssf/usermodel/ testcases/org/apache/poi/hssf/data/ testcases/org/apache/poi/hssf/usermodel/
Date Mon, 08 Sep 2008 17:43:32 GMT
Author: nick
Date: Mon Sep  8 10:43:31 2008
New Revision: 693175

URL: http://svn.apache.org/viewvc?rev=693175&view=rev
Log:
Fix bug #45761 - Support for Very Hidden excel sheets in HSSF

Added:
    poi/trunk/src/testcases/org/apache/poi/hssf/data/45761.xls   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java
    poi/trunk/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=693175&r1=693174&r2=693175&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Mon Sep  8 10:43:31 2008
@@ -37,6 +37,7 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">45761 - Support for Very Hidden
excel sheets in HSSF</action>
            <action dev="POI-DEVELOPERS" type="add">45738 - Initial HWPF support for
Office Art Shapes</action>
            <action dev="POI-DEVELOPERS" type="fix">45720 - Fixed HSSFWorkbook.cloneSheet
to correctly clone sheets with drawings</action>
            <action dev="POI-DEVELOPERS" type="fix">45728 - Fix for SlideShow.reorderSlide
in HSLF</action>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=693175&r1=693174&r2=693175&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Sep  8 10:43:31 2008
@@ -34,6 +34,7 @@
 	<!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">45761 - Support for Very Hidden
excel sheets in HSSF</action>
            <action dev="POI-DEVELOPERS" type="add">45738 - Initial HWPF support for
Office Art Shapes</action>
            <action dev="POI-DEVELOPERS" type="fix">45720 - Fixed HSSFWorkbook.cloneSheet
to correctly clone sheets with drawings</action>
            <action dev="POI-DEVELOPERS" type="fix">45728 - Fix for SlideShow.reorderSlide
in HSLF</action>

Modified: poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java?rev=693175&r1=693174&r2=693175&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java Mon Sep  8 10:43:31 2008
@@ -560,32 +560,72 @@
     }
 
     /**
-     * gets the hidden flag for a given sheet.
+     * Gets the hidden flag for a given sheet.
+     * Note that a sheet could instead be 
+     *  set to be very hidden, which is different
+     *  ({@link #isSheetVeryHidden(int)})
      *
      * @param sheetnum the sheet number (0 based)
      * @return True if sheet is hidden
      */
-
     public boolean isSheetHidden(int sheetnum) {
         return getBoundSheetRec(sheetnum).isHidden();
     }
 
     /**
+     * Gets the very hidden flag for a given sheet.
+     * This is different from the normal 
+     *  hidden flag 
+     *  ({@link #isSheetHidden(int)})
+     *
+     * @param sheetnum the sheet number (0 based)
+     * @return True if sheet is very hidden
+     */
+    public boolean isSheetVeryHidden(int sheetnum) {
+        return getBoundSheetRec(sheetnum).isVeryHidden();
+    }
+
+    /**
      * Hide or unhide a sheet
      * 
      * @param sheetnum The sheet number
      * @param hidden True to mark the sheet as hidden, false otherwise
      */
-    
     public void setSheetHidden(int sheetnum, boolean hidden) {
         getBoundSheetRec(sheetnum).setHidden(hidden);
     }
+    
+    /**
+     * Hide or unhide a sheet.
+     *  0 = not hidden
+     *  1 = hidden
+     *  2 = very hidden.
+     * 
+     * @param sheetnum The sheet number
+     * @param hidden 0 for not hidden, 1 for hidden, 2 for very hidden
+     */
+    public void setSheetHidden(int sheetnum, int hidden) {
+    	BoundSheetRecord bsr = getBoundSheetRec(sheetnum);
+    	boolean h = false;
+    	boolean vh = false;
+    	if(hidden == 0) {
+    	} else if(hidden == 1) {
+    		h = true;
+    	} else if(hidden == 2) {
+    		vh = true;
+    	} else {
+    		throw new IllegalArgumentException("Invalid hidden flag " + hidden + " given, must
be 0, 1 or 2");
+    	}
+    	bsr.setHidden(h);
+    	bsr.setVeryHidden(vh);
+    }
+    
+    
     /**
      * get the sheet's index
      * @param name  sheet name
      * @return sheet index or -1 if it was not found.
      */
-
     public int getSheetIndex(String name) {
         int retval = -1;
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java?rev=693175&r1=693174&r2=693175&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java Mon Sep  8 10:43:31
2008
@@ -36,6 +36,7 @@
     public final static short sid = 0x0085;
 
 	private static final BitField hiddenFlag = BitFieldFactory.getInstance(0x01);
+	private static final BitField veryHiddenFlag = BitFieldFactory.getInstance(0x02);
     private int field_1_position_of_BOF;
     private short field_2_option_flags;
     private byte field_3_sheetname_length;
@@ -301,11 +302,31 @@
         return sid;
     }
 
+    /**
+     * Is the sheet hidden? Different from very hidden 
+     */
     public boolean isHidden() {
 	    return hiddenFlag.isSet(field_2_option_flags);
     }
 
+    /**
+     * Is the sheet hidden? Different from very hidden 
+     */
     public void setHidden(boolean hidden) {
 	    field_2_option_flags = hiddenFlag.setShortBoolean(field_2_option_flags, hidden);
     }
+
+    /**
+     * Is the sheet very hidden? Different from (normal) hidden 
+     */
+    public boolean isVeryHidden() {
+	    return veryHiddenFlag.isSet(field_2_option_flags);
+    }
+
+    /**
+     * Is the sheet very hidden? Different from (normal) hidden 
+     */
+    public void setVeryHidden(boolean veryHidden) {
+	    field_2_option_flags = veryHiddenFlag.setShortBoolean(field_2_option_flags, veryHidden);
+    }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=693175&r1=693174&r2=693175&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Mon Sep  8 10:43:31
2008
@@ -581,7 +581,10 @@
     }
 
     /**
-     * check whether a sheet is hidden
+     * Check whether a sheet is hidden.
+     * Note that a sheet could instead be 
+     *  set to be very hidden, which is different
+     *  ({@link #isSheetVeryHidden(int)})
      * @param sheetIx Number
      * @return True if sheet is hidden
      */
@@ -589,6 +592,18 @@
         validateSheetIndex(sheetIx);
         return workbook.isSheetHidden(sheetIx);
     }
+    /**
+     * Check whether a sheet is very hidden.
+     * This is different from the normal 
+     *  hidden status  
+     *  ({@link #isSheetHidden(int)})
+     * @param sheetIx Number
+     * @return True if sheet is very hidden
+     */
+    public boolean isSheetVeryHidden(int sheetIx) {
+        validateSheetIndex(sheetIx);
+        return workbook.isSheetVeryHidden(sheetIx);
+    }
 
     /**
      * Hide or unhide a sheet
@@ -600,6 +615,19 @@
         validateSheetIndex(sheetIx);
         workbook.setSheetHidden(sheetIx, hidden);
     }
+    /**
+     * Hide or unhide a sheet.
+     *  0 = not hidden
+     *  1 = hidden
+     *  2 = very hidden.
+     * 
+     * @param sheetIx The sheet number
+     * @param hidden 0 for not hidden, 1 for hidden, 2 for very hidden
+     */
+    public void setSheetHidden(int sheetIx, int hidden) {
+        validateSheetIndex(sheetIx);
+        workbook.setSheetHidden(sheetIx, hidden);
+    }
 
     /*
      * get the sheet's index

Added: poi/trunk/src/testcases/org/apache/poi/hssf/data/45761.xls
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/45761.xls?rev=693175&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/45761.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=693175&r1=693174&r2=693175&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Mon Sep  8 10:43:31
2008
@@ -1381,4 +1381,31 @@
         assertFalse(nwb.getSheetAt(1).getForceFormulaRecalculation());
         assertTrue(nwb.getSheetAt(2).getForceFormulaRecalculation());
     }
+    
+    /**
+     * Very hidden sheets not displaying as such
+     */
+    public void test45761() {
+    	HSSFWorkbook wb = openSample("45761.xls");
+    	assertEquals(3, wb.getNumberOfSheets());
+    	
+    	assertFalse(wb.isSheetHidden(0));
+    	assertFalse(wb.isSheetVeryHidden(0));
+    	assertTrue(wb.isSheetHidden(1));
+    	assertFalse(wb.isSheetVeryHidden(1));
+    	assertFalse(wb.isSheetHidden(2));
+    	assertTrue(wb.isSheetVeryHidden(2));
+    	
+    	// Change 0 to be very hidden, and re-load
+    	wb.setSheetHidden(0, 2);
+    	
+        HSSFWorkbook nwb = writeOutAndReadBack(wb);
+
+    	assertFalse(nwb.isSheetHidden(0));
+    	assertTrue(nwb.isSheetVeryHidden(0));
+    	assertTrue(nwb.isSheetHidden(1));
+    	assertFalse(nwb.isSheetVeryHidden(1));
+    	assertFalse(nwb.isSheetHidden(2));
+    	assertTrue(nwb.isSheetVeryHidden(2));
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message