//================================================================== // Proposed additions to org.apache.poi.hssf.usermodel.HSSFWorkbook //================================================================== public static final short VISIBLE = Workbook.VISIBLE; public static final short HIDDEN = Workbook.HIDDEN; public static final short STRONG_HIDDEN = Workbook.STRONG_HIDDEN; /** * Returns true if given worksheet is hidden. * * @param iSheetnum index of worksheet to test. * @return true if given worksheet is hidden. * @throws IndexOutOfBoundsException if iSheetnum is out of range */ public boolean isHidden( int iSheetnum ) { return getWorkbook().isHidden( iSheetnum ); } /** * @param iSheetnum index of worksheet to test. * @param iOption must be one of the following constants: * VISIBLE, HIDDEN, STRONG_HIDDEN * @throws IndexOutOfBoundsException if iSheetnum is out of range * @throws RuntimeException if iOption is out of range */ public void setHidden( int iSheetnum, short iOption ) { getWorkbook().setHidden( iSheetnum, iOption ); } /** * @param sSheetName name of worksheet to be hidden/unhidden. * @param iOption must be one of the following constants: * VISIBLE, HIDDEN, STRONG_HIDDEN * @throws RuntimeException if no worksheet exists with given name. * @throws RuntimeException if iOption is out of range */ public void setHidden( String sSheetName, short iOption ) { int iSheetnum = getSheetIndex( sSheetName ); if ( iSheetnum < 0 ) throw new RuntimeException("Sheet name not found"); getWorkbook().setHidden( iSheetnum, iOption ); } /** * @param iSheetnum index of worksheet to be hidden. * @throws IndexOutOfBoundsException if iSheetnum is out of range */ public void hide( int iSheetnum ) { getWorkbook().setHidden( iSheetnum, HIDDEN ); } /** * @param sSheetName name of worksheet to be hidden * @throws RuntimeException if no worksheet exists with given name. */ public void hide( String sSheetName ) { int iSheetnum = getSheetIndex( sSheetName ); if ( iSheetnum < 0 ) throw new RuntimeException("Sheet name not found"); getWorkbook().setHidden( iSheetnum, HIDDEN ); } /** * @param iSheetnum index of worksheet to be unhidden. * @throws IndexOutOfBoundsException if iSheetnum is out of range */ public void unhide( int iSheetnum ) { getWorkbook().setHidden( iSheetnum, VISIBLE ); } /** * @param sSheetName name of worksheet to be unhidden. * @throws RuntimeException if no worksheet exists with given name. */ public void unhide( String sSheetName ) { int iSheetnum = getSheetIndex( sSheetName ); if ( iSheetnum < 0 ) throw new RuntimeException("Sheet name not found"); getWorkbook().setHidden( iSheetnum, VISIBLE ); } //========================================================== // Proposed additions to org.apache.poi.hssf.model.Workbook //========================================================== public static final short VISIBLE = 0; public static final short HIDDEN = 1; public static final short STRONG_HIDDEN = 2; /** * Returns true if given worksheet is hidden. * * @param iSheetnum index of worksheet to test. * @return true if given worksheet is hidden. * @throws IndexOutOfBoundsException if iSheetnum is out of range */ public boolean isHidden( int iSheetnum ) { BoundSheetRecord bsr = getBoundsheetRecord( iSheetnum ); return bsr.getOptionFlags() != 0; } /** * @param iSheetnum index of worksheet to test. * @param iOptions must be one of the following constants: * VISIBLE, HIDDEN, STRONG_HIDDEN * @throws IndexOutOfBoundsException if iSheetnum is out of range * @throws RuntimeException if iOption is out of range */ public void setHidden( int iSheetnum, short iOptions ) { switch( iOptions ) { default: throw new RuntimeException( "Option flag must be VISIBLE (0), HIDDEN (1) or STRONG_HIDDEN (2)" ); case VISIBLE: case HIDDEN: case STRONG_HIDDEN: BoundSheetRecord bsr = getBoundsheetRecord( iSheetnum ); bsr.setOptionFlags( (bsr.getOptionFlags() & 0xfffc) | iOptions ); } } /** * Returns the BoundsheetRecord associated with given sheet number. * * @param iSheetnum index of BoundsheetRecord to return. * @return the BoundsheetRecord at the specified position in this list. * @throws IndexOutOfBoundsException if iSheetnum is out of range * (iSheetnum < 0 || iSheetnum >= boundsheets.size()). */ protected BoundSheetRecord getBoundsheetRecord( int iSheetnum ) { return (BoundSheetRecord)boundsheets.get( iSheetnum ); } public static void main(String[] args) { TestWorkbook2 testWorkbook21 = new TestWorkbook2(); } } //============================================================================= // // In order to add the "hidden" attribute to the HSSFSheet (and Sheet) classes // the following changes must also be made... // //============================================================================= //================================================================== // Proposed additions to org.apache.poi.hssf.usermodel.HSSFWorkbook //================================================================== public HSSFWorkbook(POIFSFileSystem fs) throws IOException { // ... stuff removed while (numRecords < records.size()) { // Old version // Sheet sheet = Sheet.createSheet(records, sheetNum++, numRecords); // New version boolean bHidden = workbook.isHidden( sheetNum + 1 ); Sheet sheet = Sheet.createSheet(records, sheetNum++, numRecords, bHidden); // ... stuff removed } } //======================================================= // Proposed additions to org.apache.poi.hssf.model.Sheet //======================================================= private boolean _bHidden = false; public static Sheet createSheet(List recs, int sheetnum, int offset, boolean bHidden) { _bHidden = bHidden; } public boolean isHidden() { return _bHidden; } //=============================================================== // Proposed additions to org.apache.poi.hssf.usermodel.HSSFSheet //=============================================================== public boolean isHidden() { return getSheet().isHidden(); }