docling icon indicating copy to clipboard operation
docling copied to clipboard

ODS: hidden sheets are not detected and are exported as visible content

Open dlaszlo opened this issue 3 weeks ago • 1 comments

Bug

Content from a hidden sheet in an ODS file saved by LibreOffice Calc appears in Docling's default exports.

OdsDocumentBackend._get_sheet_content_layer (opendocument_backend.py L2677-L2685) reads table:display from the table:table element. LibreOffice Calc writes it on the style:table-properties of the sheet's table style, which is where the ODF schema defines it (style-table-properties-attlist; it is not in table-table-attlist):

<style:style style:name="ta2" style:family="table" style:master-page-name="PageStyle_5f_Hidden"><style:table-properties table:display="false" style:writing-mode="lr-tb"/>
...
<table:table table:name="Hidden" table:style-name="ta2">

The comparison could not match anyway: odfdo's get_attribute returns "false" as the bool False, and the code compares it with the string "false".

So no sheet is detected as hidden, and a hidden sheet stays in the body layer.

Impact

The hidden sheet's text is in the default Markdown, HTML and text exports and in HierarchicalChunker chunks. docling on an .ods that LibreOffice 26.2 saved from an .xlsx with a hidden sheet writes the hidden sheet's table to the Markdown file; the .xlsx itself gives that sheet the invisible layer (msexcel_backend.py L2909-L2915).

Steps to reproduce

from io import BytesIO

from docling.datamodel.base_models import DocumentStream
from docling.document_converter import DocumentConverter
from odfdo import Document, Element, Table

# A sheet hidden the way LibreOffice Calc saves it: table:display="false" on the
# style:table-properties of the sheet's automatic table style.
ods = Document("spreadsheet")
ods.body.clear()
ods.insert_style(
    Element.from_tag(
        '<style:style style:name="ta_hidden" style:family="table">'
        '<style:table-properties table:display="false"/></style:style>'
    ),
    automatic=True,
)
shown = Table("Shown")
shown.set_value("A1", "visible text")
hidden = Table("Hidden", style="ta_hidden")
hidden.set_value("A1", "hidden text")
ods.body.append(shown)
ods.body.append(hidden)
buffer = BytesIO()
ods.save(buffer)
buffer.seek(0)

doc = DocumentConverter().convert(DocumentStream(name="book.ods", stream=buffer)).document
for group in doc.groups:
    print(group.name, "->", group.content_layer.value)
print("markdown:", repr(doc.export_to_markdown()))

Output:

sheet: Shown -> body
sheet: Hidden -> body
markdown: '| visible text   |\n|----------------|\n\n| hidden text   |\n|---------------|'

Expected: sheet: Hidden -> invisible, and only the visible table in the Markdown.

Possible fix

Read table:display from the style:table-properties of the sheet's table style, as the raw attribute string.

Fixing the layer alone makes a hidden sheet's page 0 × 0, because _find_page_size iterates the body layer only (L2660), so the fix depends on the page-size change in #5300 (or the page-extent helper in docling-project/docling-core#1013). Without that change, the default Markdown, HTML and text exports, HierarchicalChunker and a JSON reload clamp the hidden table box to (0, 0, 0, 0) with two UserWarnings, and export_to_doctags() and export_to_doclang() raise ZeroDivisionError. A draft PR with the fix and a regression test follows; it will be marked ready once that change is merged.

Related, not covered here: ODS hidden rows and columns (table:visibility="collapse") are exported too; #4620 is the XLSX counterpart.

Docling version

$ docling --version
Docling version: 2.150.0
Docling Core version: 2.106.0
Docling IBM Models version: 4.0.4
Docling Parse version: 7.25.0
Python: cpython-314 (3.14.4)
Platform: Linux-7.0.0-43-generic-x86_64-with-glibc2.43

odfdo 3.27.3, LibreOffice 26.2.6.3. The permalinks are to the docling v2.150.0 tag; both files are unchanged on main.

Python version

Python 3.14.4

dlaszlo avatar Nov 11 '26 21:11 dlaszlo

Classification labels added: bug, priority:medium, odf.

These labels are advisory. Maintainers can correct them. The workflow preserves these corrections.

github-actions[bot] avatar Nov 16 '26 15:11 github-actions[bot]