Skip to content

cell.width has no effect to the cell width #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
timothyleung opened this issue Jan 19, 2016 · 7 comments
Closed

cell.width has no effect to the cell width #247

timothyleung opened this issue Jan 19, 2016 · 7 comments

Comments

@timothyleung
Copy link

I tried to change the width of a specific cell in a table using the following code

table = document.add_table(rows=2, cols=2)
table.style = 'DP-Plain 1'
table.autofit = False
table.allow_autofit = False
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Finding #1'
hdr_cells[0].width = Inches(2.5) // I tried to change the width of this cell to 2.5 inches
hdr_cells[1].text = 'Medium'

row_cells = table.rows[1].cells
row_cells[0].text = "heading1"
row_cells[1].text = "content1"

row_cells = table.add_row().cells
row_cells[0].text = "heading2"
row_cells[1].text = "content2"

However, my cell still having the same size as others.
Am I doing it wrong? Thanks!

@scanny
Copy link
Contributor

scanny commented Jan 19, 2016

Try setting the width on all the cells in that column to the width you want. You could also try setting the column width itself (as well as cells).

The column width algorithm for Word is complex and fairly arbitrary it seems. It appears to take requests for size more as guidelines rather than commands :)

@timothyleung
Copy link
Author

I tried to set the first column to Inches(1.0) as well but there are no effect on the table as well.

table = document.add_table(rows=2, cols=2)
table.style = 'DP-Plain 1'
table.autofit = False
table.allow_autofit = False

table.columns[0].width = Inches(1.0) // Try to set column 0 width to 1.0

hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Finding #1'
hdr_cells[0].width = Inches(2.5)
hdr_cells[1].text = 'Medium'

row_cells = table.rows[1].cells
row_cells[0].text = "heading1"
row_cells[1].text = "content1"
row_cells[1].paragraphs[0].style.name = 'Body Text'

@timothyleung
Copy link
Author

Oh, ok. I set all the cells to the same width as the column one by one and it is working now. So, the library do not support setting a row with cells that have different width than the other rows?

@scanny
Copy link
Contributor

scanny commented Jan 20, 2016

Word doesn't allow that. If you see something that looks like that, it's done by merging certain cells. A column is the same width from top to bottom.

@timothyleung
Copy link
Author

OK cool. I archived what I want with cell merging. That makes the code much more complicated though. Should I close this or leave it open?

@scanny scanny closed this as completed Jan 21, 2016
@de-adshot
Copy link

Did we have any solution for this? Am facing the same issue.

@gian-didom
Copy link

«Word doesn't allow that. If you see something that looks like that, it's done by merging certain cells. A column is the same width from top to bottom.»

That is not true since I can set a single cell width in word by selecting it before resizing the column. Does this mean that internally word creates a cell merging with this operation?

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

No branches or pull requests

4 participants