Fix bug #45761 - Support for Very Hidden excel sheets in HSSF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@693175 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
770dfcf4a4
commit
a7ae05977b
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
<!-- Don't forget to update status.xml too! -->
|
<!-- Don't forget to update status.xml too! -->
|
||||||
<release version="3.1.1-alpha1" date="2008-??-??">
|
<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="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">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>
|
<action dev="POI-DEVELOPERS" type="fix">45728 - Fix for SlideShow.reorderSlide in HSLF</action>
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
<!-- Don't forget to update changes.xml too! -->
|
<!-- Don't forget to update changes.xml too! -->
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.1.1-alpha1" date="2008-??-??">
|
<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="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">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>
|
<action dev="POI-DEVELOPERS" type="fix">45728 - Fix for SlideShow.reorderSlide in HSLF</action>
|
||||||
|
@ -560,32 +560,72 @@ public final class Workbook implements Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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)
|
* @param sheetnum the sheet number (0 based)
|
||||||
* @return True if sheet is hidden
|
* @return True if sheet is hidden
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public boolean isSheetHidden(int sheetnum) {
|
public boolean isSheetHidden(int sheetnum) {
|
||||||
return getBoundSheetRec(sheetnum).isHidden();
|
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
|
* Hide or unhide a sheet
|
||||||
*
|
*
|
||||||
* @param sheetnum The sheet number
|
* @param sheetnum The sheet number
|
||||||
* @param hidden True to mark the sheet as hidden, false otherwise
|
* @param hidden True to mark the sheet as hidden, false otherwise
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void setSheetHidden(int sheetnum, boolean hidden) {
|
public void setSheetHidden(int sheetnum, boolean hidden) {
|
||||||
getBoundSheetRec(sheetnum).setHidden(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
|
* get the sheet's index
|
||||||
* @param name sheet name
|
* @param name sheet name
|
||||||
* @return sheet index or -1 if it was not found.
|
* @return sheet index or -1 if it was not found.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public int getSheetIndex(String name) {
|
public int getSheetIndex(String name) {
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ public final class BoundSheetRecord extends Record {
|
|||||||
public final static short sid = 0x0085;
|
public final static short sid = 0x0085;
|
||||||
|
|
||||||
private static final BitField hiddenFlag = BitFieldFactory.getInstance(0x01);
|
private static final BitField hiddenFlag = BitFieldFactory.getInstance(0x01);
|
||||||
|
private static final BitField veryHiddenFlag = BitFieldFactory.getInstance(0x02);
|
||||||
private int field_1_position_of_BOF;
|
private int field_1_position_of_BOF;
|
||||||
private short field_2_option_flags;
|
private short field_2_option_flags;
|
||||||
private byte field_3_sheetname_length;
|
private byte field_3_sheetname_length;
|
||||||
@ -301,11 +302,31 @@ public final class BoundSheetRecord extends Record {
|
|||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the sheet hidden? Different from very hidden
|
||||||
|
*/
|
||||||
public boolean isHidden() {
|
public boolean isHidden() {
|
||||||
return hiddenFlag.isSet(field_2_option_flags);
|
return hiddenFlag.isSet(field_2_option_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the sheet hidden? Different from very hidden
|
||||||
|
*/
|
||||||
public void setHidden(boolean hidden) {
|
public void setHidden(boolean hidden) {
|
||||||
field_2_option_flags = hiddenFlag.setShortBoolean(field_2_option_flags, 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -581,7 +581,10 @@ public class HSSFWorkbook extends POIDocument
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* @param sheetIx Number
|
||||||
* @return True if sheet is hidden
|
* @return True if sheet is hidden
|
||||||
*/
|
*/
|
||||||
@ -589,6 +592,18 @@ public class HSSFWorkbook extends POIDocument
|
|||||||
validateSheetIndex(sheetIx);
|
validateSheetIndex(sheetIx);
|
||||||
return workbook.isSheetHidden(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
|
* Hide or unhide a sheet
|
||||||
@ -600,6 +615,19 @@ public class HSSFWorkbook extends POIDocument
|
|||||||
validateSheetIndex(sheetIx);
|
validateSheetIndex(sheetIx);
|
||||||
workbook.setSheetHidden(sheetIx, hidden);
|
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
|
* get the sheet's index
|
||||||
|
BIN
src/testcases/org/apache/poi/hssf/data/45761.xls
Normal file
BIN
src/testcases/org/apache/poi/hssf/data/45761.xls
Normal file
Binary file not shown.
@ -1381,4 +1381,31 @@ public final class TestBugs extends TestCase {
|
|||||||
assertFalse(nwb.getSheetAt(1).getForceFormulaRecalculation());
|
assertFalse(nwb.getSheetAt(1).getForceFormulaRecalculation());
|
||||||
assertTrue(nwb.getSheetAt(2).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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user