GithubHelp home page GithubHelp logo

Comments (5)

proxyblue avatar proxyblue commented on August 20, 2024

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 πŸ‘

from python-docx.

jgadelange avatar jgadelange commented on August 20, 2024

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

from python-docx.

onlyjus avatar onlyjus commented on August 20, 2024

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.

from python-docx.

onlyjus avatar onlyjus commented on August 20, 2024

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

from python-docx.

scanny avatar scanny commented on August 20, 2024

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.

from python-docx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.