All I really want to know is whether a worksheet is hidden or not. It would be nice if there was a simple boolean method on HSSFSheet that showed this attribute. It would be so simple to do. But the way Workbook hides the boundsheets ArrayList, this is just not possible. It seems like the only thing that Workbook doesn't report about any given BoundsheetRecord is the option flag. Here's what I propose for HSSFWorkbook: /** * 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 ) { getWorkbook().isHidden( iSheetnum ); } Then in Workbook: /** * 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.getOptions() != 0; } /** * 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 ); }
Created attachment 14530 [details] Should also be able to set the options flag (to hide/unhide the worksheet) I have added the ability to set the options flag to my proposed enhancement. As well, I have added the ability to select a sheet by name as well as by index (i.e. sheet number). I also outline how the hidden attribute could be added to the Sheet and HSSFSheet classes.
This is useful, thanks, but could you -- 1. Namespace the contants (SHEET_VISIBILITY_VISIBLE, SHEET_VISIBILITY_HIDDEN etc. for example) 2. Attach these as a diff 3. Add testcases. That would be very helpful, else someone will have to spend a couple of hours to check this in.
*** Bug 34075 has been marked as a duplicate of this bug. ***
Hi, The changes to the HSSFWorkbook/Workbook in the attachment look very much like what I need too. But the changes to make the hidden attribute available to HSSFSheet/Sheet do not make sense to me. These isHidden methods do not reflect changes made through the HSSFWorkbook/Workbook. So you end up getting different results if you ask the Workbook and the Sheet. To fix this, we would need to pass not ony the hidden flag to the sheet, but a reference to it's boundsheet record in the constructor. But that would also mean a change in the way createSheet and cloneSheet are working...
Use HSSFWorkbook.isSheetHidden(int sheetNumber) to determine if worksheet is hidden. Yegor
Thanks for taking the time to fix this and annotate the fix.