Feature request: ignore hidden cells in table_to_sheet/book #1115
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#1115
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?
It would be great if SheetJS ignores hidden rows and cells when parsing a DOM table using the
table_to_sheet
andtable_to_book
functions.For example, the following table:
Would be parsed as:
Detecting whether the cell is hidden can be done by detecting a
display: none
style:Ignoring hidden cells and rows can be optional:
If you support this feature, I can make a pull request.
There are funny corner cases surrounding the interaction of merge cells (TD with rowspan >1 and colspan > 1). For example, suppose you had a table where B2:D3 were merged:
If you hide A2 (setting
style="display:none;
, most HTML rendering engines will display as if you specified:Which would be drawn like
Is that the right answer? Or should non-display TD elements be treated as if they had no contents (generate a stub cell or nothing at all)?
@SheetJSDev I think that a user expects to see in a worksheet exactly what he/she sees in the browser, therefore SheetJS should behave the same as browsers (completely ignore hidden cells).
@Finesse It's probably best to follow Excel's example. If you take the first example, save as an HTML file, and open in Excel, you will find that it hides the row but does not hide the column:
So the specific approach that we'd be willing to accept is: if available, use
getComputedStyle
on the TR element to determine whether the TR is visible. If it is not visible, mark the row as hidden. The feature is controlled in the worksheet!row
array@SheetJSDev What about cells (
<td/>
s and<th/>
s)? Must hidden cells be ignored? I insist to ignore them to conform the HTML behaviour. This is the key feature I request.Should the described behaviour be the default behaviour? Should there be a possibility to enable/disable it using the
ignoreHiddenRows
andignoreHiddenCells
parameters?Excel treats the singleton
<td/>
and<th/>
as if they were empty text (stub cells). It probably makes sense to generate stub cells ifsheetStubs
is true (to be consistent with the other formats).The original objection was based on how Excel handles the underlying HTML, but upon reflection your argument makes sense. Let's try:
The default behavior should include every cell and only hide rows if the TR element is hidden.
Create a new
display
option (default false) that omits every hidden cell and every hidden row if true (as if the hidden cells were not included in the first place).@SheetJSDev Let's recap it.
There will be a new option called
display
in thetable_to_sheet
andtable_to_book
methods. The default value of this option isfalse
.If
display
value isfalse
, the result table (created from the HTML from my first example) looks this way:If
display
value istrue
, the result table looks this way:Is it correct?
@Finesse correct. That makes the most sense since the default behavior lines up with how Excel handles HTML tables while the new behavior lines up with what people would expect.
https://www.caniuse.com/#feat=getcomputedstyle suggests IE9+ support getComputedStyle, so it should not be assumed to exist (IE8 is still a target in the browser test matrix). If getComputedStyle is not available, just proceed as if nothing was hidden.
@SheetJSDev Ok! I will make a pull request in a few days.