Bug 34072 - No easy way to tell if worksheet is hidden (no access to the BoundsheetRecord option flag)
Summary: No easy way to tell if worksheet is hidden (no access to the BoundsheetRecord...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.5-FINAL
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
: 34075 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-03-18 12:24 UTC by Bob White
Modified: 2008-05-17 06:56 UTC (History)
1 user (show)



Attachments
Should also be able to set the options flag (to hide/unhide the worksheet) (6.69 KB, text/plain)
2005-03-22 01:40 UTC, Bob White
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bob White 2005-03-18 12:24:00 UTC
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 &lt; 0 || iSheetnum &gt;= boundsheets.size())</tt>.
   */
  protected BoundsheetRecord getBoundsheetRecord( int iSheetnum )
  { 
    return (BoundsheetRecord)boundsheets.get( iSheetnum );
  }
Comment 1 Bob White 2005-03-22 01:40:31 UTC
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.
Comment 2 Avik Sengupta 2005-04-22 13:23:56 UTC
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. 
Comment 3 Avik Sengupta 2005-04-22 13:24:55 UTC
*** Bug 34075 has been marked as a duplicate of this bug. ***
Comment 4 Jochen Klein 2005-04-22 22:02:20 UTC
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...
Comment 5 Yegor Kozlov 2008-05-17 06:43:18 UTC
Use HSSFWorkbook.isSheetHidden(int sheetNumber) to determine if worksheet is hidden.

Yegor
Comment 6 Bob White 2008-05-17 06:56:32 UTC
Thanks for taking the time to fix this and annotate the fix.