From 3306543d99f78562216b93a0dc3583ed6ffee5c9 Mon Sep 17 00:00:00 2001 From: Aaron Dais Date: Wed, 29 Apr 2026 23:53:58 -0500 Subject: [PATCH] Export table cell background color to HTML (Issue #230) --- pydocx/export/html.py | 3 +++ pydocx/openxml/wordprocessing/table_cell_properties.py | 1 + 2 files changed, 4 insertions(+) diff --git a/pydocx/export/html.py b/pydocx/export/html.py index 18e3ea53..d6744c36 100644 --- a/pydocx/export/html.py +++ b/pydocx/export/html.py @@ -668,6 +668,9 @@ def export_table_cell(self, table_cell): attrs['colspan'] = colspan if rowspan > 1: attrs['rowspan'] = rowspan + fill = getattr(table_cell.properties, 'shading', None) + if fill and fill != 'auto': + attrs['style'] = 'background-color:#%s;' % fill tag = HtmlTag('td', **attrs) numbering_spans = self.yield_numbering_spans(table_cell.children) diff --git a/pydocx/openxml/wordprocessing/table_cell_properties.py b/pydocx/openxml/wordprocessing/table_cell_properties.py index 2a94c9b0..ce40db3e 100644 --- a/pydocx/openxml/wordprocessing/table_cell_properties.py +++ b/pydocx/openxml/wordprocessing/table_cell_properties.py @@ -14,6 +14,7 @@ class TableCellProperties(XmlModel): grid_span = XmlChild(name='gridSpan', attrname='val') vertical_merge = XmlChild(name='vMerge', type=lambda el: dict(el.attrib)) # noqa + shading = XmlChild(name='shd', attrname='fill') def should_close_previous_vertical_merge(self): # If vMerge is omitted, then this cell shall not be part of any