1212
problems with colspan and rowspans · Issue #25 · dfop02/html4docx · GitHub
Skip to content

problems with colspan and rowspans #25

@michkam89

Description

@michkam89

Hi,

I have this simple table with cells that span over 2 rows and/or columns:

Image
from html4docx import HtmlToDocx
from docx import Document

html_str = """<table border="1" cellspacing="0" cellpadding="4">
  <tr>
    <th rowspan="2">Region</th>
    <th colspan="2">Sales (CHF millions)</th>
  </tr>
  <tr>
    <th>2024</th>
    <th>2023</th>
  </tr>
  <tr>
    <td>United States</td>
    <td>22,456</td>
    <td>20,892</td>
  </tr>
  <tr>
    <td>Europe</td>
    <td>8,147</td>
    <td>7,634</td>
  </tr>
</table>"""

parser = HtmlToDocx()
doc = Document()
parser.table_style = 'Table Grid'
parser.add_html_to_document(html_str, doc)
doc.save('test_table.docx')

But in Google Docs this is not reflected and values are moved to the left:
Image

Is this something that can be fixed? Or maybe the table should be written differently? I'm using version 1.0.8.
thanks!

Metadata

Metadata

Assignees

Labels

New FeatureNew feature or requestbugSomething isn't workinggood first issueGood for newcomers

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions