Comments (5)
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.
I would also like the possibility to set a colspan for a cell.
from python-docx.
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.
I started to get these functions working: colspan, and cell shading (color, etc.). merge request
from python-docx.
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)
- ζεΌη©Ίηdocxζζ‘£ζΆζ₯ι
- Inline support for SVG file stream HOT 3
- How to add internal top and bottom table cell spacings?
- Inserting a new page before last page in the word document using python HOT 1
- Auto refresh Table of Contents using docx HOT 1
- OSS-Fuzz Integration
- Highlight certain words of a paragraph to bold
- Paragraphs/Numbering in Table of Contents Document Regions HOT 3
- no read apis HOT 1
- feat: distinguish "no such file" from "not a ZIP"
- Workaround to set <w:bidi/> property on a paragraph's properties <w:pPr>? HOT 2
- docx2pdf issue HOT 1
- Python-docx detects a single paragraph with a single run with a single style -- when it should detect multiple paragraphs each having their own style HOT 9
- How do I add an xml object by coordinates?
- Values in tables are being splitted into multiple rows if there is \n in them HOT 2
- easily replacing / removing&adding image or text in header HOT 2
- support for Text Form Fields and Checkboxes
- Setting placeholder text in list of tables via field code 'TOC \\h \\z \\c "Table"'
- custom_xml_parts not available on Linux HOT 1
- Autoescape should be TRUE by default HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-docx.