aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-05-02 11:48:41 +0100
committerMichael Williamson <mike@zwobble.org>2016-05-02 11:48:41 +0100
commita0155bb9c522b9b008ad3933ffcb9609b0f698e7 (patch)
treed3740b735a409b0a8045fad9dfdefe83b264fb0e /mammoth
parent85ff4da3812222eaa59b4be434c9118af85ced1b (diff)
Read colspan for table cells
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/documents.py9
-rw-r--r--mammoth/docx/body_xml.py15
2 files changed, 21 insertions, 3 deletions
diff --git a/mammoth/documents.py b/mammoth/documents.py
index d837556..7f17f3e 100644
--- a/mammoth/documents.py
+++ b/mammoth/documents.py
@@ -48,7 +48,7 @@ class TableRow(HasChildren):
@cobble.data
class TableCell(HasChildren):
- pass
+ colspan = cobble.field()
@cobble.data
class LineBreak(Element):
@@ -111,7 +111,12 @@ bookmark = Bookmark
table = Table
table_row = TableRow
-table_cell = TableCell
+def table_cell(children, colspan=None):
+ if colspan is None:
+ colspan = 1
+ return TableCell(children=children, colspan=colspan)
+
+
line_break = LineBreak
def numbering_level(level_index, is_ordered):
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py
index f3166f5..a44169a 100644
--- a/mammoth/docx/body_xml.py
+++ b/mammoth/docx/body_xml.py
@@ -164,8 +164,21 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
def table_cell(element):
+ gridspan = element \
+ .find_child_or_null("w:tcPr") \
+ .find_child_or_null("w:gridSpan") \
+ .attributes.get("w:val")
+
+ if gridspan is None:
+ colspan = 1
+ else:
+ colspan = int(gridspan)
+
return _read_xml_elements(element.children) \
- .map(documents.table_cell)
+ .map(lambda children: documents.table_cell(
+ children=children,
+ colspan=colspan
+ ))
def read_child_elements(element):