[Question] How to tell if a worksheet is hidden #464
Labels
No Label
DBF
Dates
Defined Names
Features
Formula
HTML
Images
Infrastructure
Integration
International
ODS
Operations
Performance
PivotTables
Pro
Protection
Read Bug
SSF
SYLK
Style
Write Bug
good first issue
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#464
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This xlsx module has been working great!
I know a worksheet can be hidden/unhidden, and I would like to know if there is a way to tell if a particular sheet is hidden or not using this xlsx module. Is it supported?
Hi. Having exactly the same problem. I was reading the code and found this method:
As you can see there is a hidden property, which I suposse should have one of 3 states (visible, hidden, very hidden)
The problem is that it always have value: 0 (tested on xls with hidden datasheets)
Any ideas, how to read that Excel flag?
@Thowk good catch!
That comment points to section 2.4.28 of the [MS-XLS] spec. Web link
https://msdn.microsoft.com/en-us/library/dd773237(v=office.12).aspx
Based on the layout, the hidden state is stored as the lowest 2 bits of the fifth byte. The correct line should be:
var hidden = blob.read_shift(1) & 0x03
.Even with the aforementioned correction, the hidden state is not stored anywhere. To follow along, in the parse_workbook function jump down to the
BoundSheet8
case:So this just captures the position in the stream and stores the name of the sheet. We have to actually save the hidden state somewhere (it is passed along as
val.hs
in that block). This raises 2 questions:XLSB and XLS both store the metadata in the workbook object so it's probably best to stick it somewhere in the object, probably as an array of sheet-level properties. But it is also tempting to just store it in the sheet objects themselves (with a key like
!visibility
)XLSX uses string values; XLS and XLSB use numbers, and VBA actually uses a different set of numbers:
xlSheetVisible
"visible"
xlSheetHidden
"hidden"
xlSheetVeryHidden
"veryHidden"
I think the VBA numbers differ from XLS/XLSB because
0
is commonly the default value for the file formats whereas VBA is using the serialized equivalent oftrue
andfalse
.(VBA is relevant here because, as far as I can tell, the only way to set a worksheet to "very hidden" is to set the Visible property of the worksheet in the Visual Basic editor or in a VBA macro)
Thank you @SheetJSDev for help. Now it works, after removing right-shift operator (additional & 0x03 is optional I guess. Assuming that unused bits are always 0).
For me, this msdn Documentation is confusing. Their bits order are in different notation (big endian vs little endian (?), but I'm not sure if I understand that correctly.
For my specyfic needs, I simply added additional property to workbook like this:
The best for user will be to normalize visibility states across all workbook extensions.
I would like to add PR for that, but that need more complex changes, and tests. I'll think about that.
The final resolution is to store the metadata in the workbook's
Workbook.Sheets[n].Hidden
properties. The value 0 will correspond to visible, while 1 is hidden and 2 is very hidden. This ensures that !!Workbook.Sheets[n].Hidden will be true for hidden and very hidden sheets