Bug 61699 - Implement XSSFWorkbook#isHidden()
Summary: Implement XSSFWorkbook#isHidden()
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 4.0.x-dev
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-31 00:46 UTC by Javen O'Neal
Modified: 2017-10-31 15:45 UTC (History)
0 users



Attachments
Empty workbook with a hidden workbook view (7.48 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2017-10-31 00:46 UTC, Javen O'Neal
Details
Patch to add isHidden(), setHidden(boolean), isHidden(int), setHidden(int, boolean) (7.50 KB, patch)
2017-10-31 02:27 UTC, Javen O'Neal
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Javen O'Neal 2017-10-31 00:46:09 UTC
Created attachment 35476 [details]
Empty workbook with a hidden workbook view

From Users@POI mailing list: https://lists.apache.org/thread.html/4c6b6800d165d90374d3ad3ea49bbd1509c3a4d0dc093d0f1d597965@%3Cuser.poi.apache.org%3E

I was able to create a hidden window in Microsoft Excel 2013 only when there were multiple views of a workbook open.
View > Window > New Window to create a 2nd view of the active workbook
View > Window > Hide to hide the active view of the active workbook

In the XML:
xl/workbook.xml:
 <workbook xmlns="..." ...>
     ...
     <bookViews>
         <workbookView xWindow="0" yWindow="0" windowWidth="16920" windowHeight="10980"/>
+        <workbookView visibility="hidden" xWindow="0" yWindow="0" windowWidth="16920" windowHeight="10980"/>
     </bookViews>
     ...
 </workbook>

xl/worksheets/sheet1.xml:
 <worksheet xmlns="..." ...>
     ...
     <sheetViews>
         <sheetView tabSelected="1" workbookViewId="0"/>
+        <sheetView tabSelected="1" workbookViewId="1"/>
     </sheetViews>
     ...
 </worksheet>
Comment 1 Javen O'Neal 2017-10-31 01:36:59 UTC
HSSFWorkbook implemented isHidden/setHidden as the visibility of the first workbook view (InternalWorkbook.getWindowOne().getHidden()).

The correct behavior would seem to let the user specify the index of the window (view) and return the visibility of that window (view).

POI currently doesn't have functions for creating workbook views.

Being that Microsoft Excel doesn't allow you to hide every window view of a workbook, it's likely you'll end up with a corrupt workbook if you hide the only view on a workbook.
Comment 2 Javen O'Neal 2017-10-31 02:27:20 UTC
Created attachment 35477 [details]
Patch to add isHidden(), setHidden(boolean), isHidden(int), setHidden(int, boolean)

Being able to set workbook window views as hidden isn't very useful without being able to create and delete workbook views.

This gets more complicated because of bookviews and sheetviews

> CTWorkbook.getBookViews().addNewWorkbookView();
> CTWorkbook.getBookViews().removeWorkbookView(int i);

http://www.datypic.com/sc/ooxml/e-ssml_workbookView-1.html
http://www.datypic.com/sc/ooxml/e-ssml_customWorkbookView-1.html
http://www.datypic.com/sc/ooxml/a-visibility-1.html
Comment 3 Dominik Stadler 2017-10-31 15:45:23 UTC
Comments from Mark:

In my testing, Excel 2016, I can hide a workbook by selecting View->Hide. I can do that even if it is the only workbook open. The XML is in workbook.xml and looks like this:

<bookViews>
   <workbookView windowHeight="9600" windowWidth="17595" yWindow="255" xWindow="225" visibility="hidden"/>
</bookViews>

I can close out of Excel with the only workbook hidden, and it allows me to save it as hidden. When I re-open that workbook, it starts out hidden.
---------------------------------------------------------------------
For sheets, once again Excel 2016, I cannot hide the last visible sheet. So it appears that Excel handles Sheets and workbooks differently. One potential reason to have hidden workbooks is if you have a workbook with just macros in it, and you have that in your XLSTART library [User library]/AppData/Roaming/Microsoft/Excel/XLSTART, then that workbook will open every time you open Excel, and you really want that workbook to be hidden, but open with no visible window views.