Skip to content

correct "merge from rows"#24

Open
code4101 wants to merge 1 commit intomartsberger:masterfrom
code4101:patch-2
Open

correct "merge from rows"#24
code4101 wants to merge 1 commit intomartsberger:masterfrom
code4101:patch-2

Conversation

@code4101
Copy link

if rowspan > 1 or colspan > 1:
worksheet.merge_cells(start_row=row, start_column=column,
end_row=row + rowspan - 1, end_column=column + colspan - 1)
cell = worksheet.cell(row=row, column=column)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the error might have been here. What happens if we do column=column + colspan - 1 on this line instead of the other change?

Copy link
Author

@code4101 code4101 Mar 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

column=column + colspan - 1 can't solve this error:

from tablepyxl import tablepyxl

table = """<table>
  <tr>
    <th colspan="2" rowspan="2">a1</th>
    <th colspan="2">c1</th>
  </tr>
  <tr>
    <td rowspan="2">c2</td>
    <td>d2</td>
  </tr>
  <tr>
    <td>a3</td>
    <td>b3</td>
    <td>d3</td>
  </tr>
</table>"""

tablepyxl.document_to_xl(table, "test.xlsx")
# AttributeError: 'MergedCell' object has no attribute 'value'

table

we can add this code before cell = worksheet.cell(row=row, column=column) to analyse this bug:

print(f'We think we are in row={row}, column={column},',
      f'And now actually in {table_cell.value}, ', table_cell.element.attrib)
We think we are in row=1, column=1, And now actually in a1,  {'colspan': '2', 'rowspan': '2'}
We think we are in row=1, column=3, And now actually in c1,  {'colspan': '2'}
We think we are in row=2, column=1, And now actually in c2,  {'rowspan': '2'}
raise AttributeError: 'MergedCell' object has no attribute 'value'

In row=2, we think we are start from column=1, but actually A2 and B2 were already builded from "a1", so I judge MergedCell to skip them and shift to the actually column=3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants