Skip to content

feature: _Column.width #18

Closed
Closed

Description

@holyoaks

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.

Activity

  1. proxyblue commented on Mar 11, 2014

    @proxyblue

    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 👍

  2. jgadelange commented on Mar 15, 2014

    @jgadelange

    I would also like the possibility to set a colspan for a cell.

  3. onlyjus commented on Mar 24, 2014

    @onlyjus
    Contributor

    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.

  4. onlyjus commented on Mar 26, 2014

    @onlyjus
    Contributor

    I started to get these functions working: colspan, and cell shading (color, etc.). merge request

  5. added this to the milestone on May 1, 2014
  6. modified the milestone: on May 13, 2014
  7. changed the title [-]Allow setting table column and row properties - enhancement[/-] [+]feature: set table column width[/+] on Jun 20, 2014
  8. scanny commented on Jul 14, 2014

    @scanny
    Contributor

    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 off
    table.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.

  9. changed the title [-]feature: set table column width[/-] [+]feature: _Column.width[/+] on Jul 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions