ASF Bugzilla – Attachment 14530 Details for
Bug 34072
No easy way to tell if worksheet is hidden (no access to the BoundsheetRecord option flag)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Should also be able to set the options flag (to hide/unhide the worksheet)
Proposed POI enhancement.txt (text/plain), 6.69 KB, created by
Bob White
on 2005-03-22 01:40:31 UTC
(
hide
)
Description:
Should also be able to set the options flag (to hide/unhide the worksheet)
Filename:
MIME Type:
Creator:
Bob White
Created:
2005-03-22 01:40:31 UTC
Size:
6.69 KB
patch
obsolete
>//================================================================== >// 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 > * <tt>(iSheetnum < 0 || iSheetnum >= boundsheets.size())</tt>. > */ > 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(); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 34072
: 14530