You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Really liking the new api, but I have a need to set column widths for a table and am unable to. I would appreciate this module being enhanced to allow for setting column and row properties such as width and height.
I'd like to second this feature request. Python-docx is creating a table where the amount of data in the table is dictating the width of the table. This may be okay for small amounts of data, but when you have a two column scenario where on the left you have a title, and on the right you have the detail - and the detail spans multiple lines, the content on the left is pushed to the point of being unreadable.
I think for now, I'll have to use paragraphs rather than a table, but it would be really handy to have this as a feature for the future 👍
I added a read/write _Column.width property in v0.6.0 about a month ago but it didn't seem to do anything so I didn't mention it. Turns out it only really affects the table layout when "auto-fit" is turned off. I just added a read/write Table.autofit property in v0.7.3 and using the two together gives you strict control over the rendered column widths.
So something like this:
table=document.add_table(rows=2, cols=2)
table.autofit=False# defaults to True, so have to explicitly turn it offtable.columns[0].width=Inches(1.5)
table.columns[1].width=Inches(2.5)
will produce a table where the first column is 1.5" wide and the second 2.5" wide and those widths will not be affected by the relative lengths of what you put in the table cells.
There is also now a read/write _Cell.width property which allows you to make those settings at the cell level. I haven't experimented with how those widths interact, but I do know that in Word, when you set the column width, it sets the widths of all the cells in that column to match.
Let us know how you go :)
Closing this one now. If you want some of the other features you mentioned please open a separate issue for each along with some description of your use case like @louiscremen provided above so we know what we're shooting for.
Activity
proxyblue commentedon Mar 11, 2014
I'd like to second this feature request. Python-docx is creating a table where the amount of data in the table is dictating the width of the table. This may be okay for small amounts of data, but when you have a two column scenario where on the left you have a title, and on the right you have the detail - and the detail spans multiple lines, the content on the left is pushed to the point of being unreadable.
I think for now, I'll have to use paragraphs rather than a table, but it would be really handy to have this as a feature for the future 👍
jgadelange commentedon Mar 15, 2014
I would also like the possibility to set a colspan for a cell.
onlyjus commentedon Mar 24, 2014
I'd like to second this feature request. And second the colspan.
I have been staring at the code for ~1/2 day now trying to figure out how to add it but I keep getting lost in how the oxml/table.py works.
onlyjus commentedon Mar 26, 2014
I started to get these functions working: colspan, and cell shading (color, etc.). merge request
[-]Allow setting table column and row properties - enhancement[/-][+]feature: set table column width[/+]scanny commentedon Jul 14, 2014
I added a read/write
_Column.widthproperty in v0.6.0 about a month ago but it didn't seem to do anything so I didn't mention it. Turns out it only really affects the table layout when "auto-fit" is turned off. I just added a read/writeTable.autofitproperty in v0.7.3 and using the two together gives you strict control over the rendered column widths.So something like this:
will produce a table where the first column is 1.5" wide and the second 2.5" wide and those widths will not be affected by the relative lengths of what you put in the table cells.
There is also now a read/write
_Cell.widthproperty which allows you to make those settings at the cell level. I haven't experimented with how those widths interact, but I do know that in Word, when you set the column width, it sets the widths of all the cells in that column to match.Let us know how you go :)
Closing this one now. If you want some of the other features you mentioned please open a separate issue for each along with some description of your use case like @louiscremen provided above so we know what we're shooting for.
[-]feature: set table column width[/-][+]feature: _Column.width[/+]