-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
How do i set table style #9
Comments
I'm sorry,i just understood what's the alpha version mean. so , Im waiting beta version. |
table = document.add_table(rows, cols)
table.style = 'TableGrid' http://python-docx.readthedocs.org/en/latest/api/table.html#docx.table.Table.style |
Yes,I konw that ,But if i want set color to table , how can i do that, for example
and i need set font style , like ,color ,size ,and so on. |
There's currently no way to define table styles within python-docx. However if the "template" document you start with contains table styles, you can use them by name as above. So if you want a customized table style, just customize it in the template document you're using and apply it by name to the table. |
Thanks scanny, |
paste in the code you're using to open the document so I can see, like: document = Document('base.docx') |
|
Because, My Project is website ,so the code maybe too long , so give me some information about how to set 'template ' , that's okay. |
What you need to do is open a document in your Document() call, not just use the default.
After that you start a new document in python-docx using |
thanks very much! |
glad it worked out Keith :) |
I want to change font size of table content. I tried lots. |
It seems the font of the previous paragraph is reused (which is a problem from Word itself). I used this not-so-beautiful workaround:
Then, the next table will have the deleted paragraph's font size. Code:
|
You have to set it using Document object which contains all the styles. https://python-docx.readthedocs.io/en/latest/user/styles-understanding.html#table-styles-in-default-template document = Document() |
The above solution works fine if you start with the template file, but I find myself in a situation where I'm injecting tables into an existing .docx file (which doesn't stay static and can change, so I can't do my template creation trick there), meaning that I use a separate Document() to create the table and then inject it to the main file. That means that what ever I do with the styles of the table file, all of that gets lost once the table goes to the main file and I'm left with just the standard Table Grid as my choice. Are there any other options for me here or am I doomed? I also need to do things such as color the background of a cell depending on the content, also something that would get lost after injecting the tables to the main file. Are there any alternatives or longer solutions I could look into, or is this the pinnacle of what python can do for me when it comes to working with .docx files? Many thanks to whoever can provide some insights. |
Hi scanny.
How do i set table style?
When i using
I search the API , but i didn't find method do it, I need set table size and width and height and color and so on.
"Cell class" also didn't find any method support it.
The text was updated successfully, but these errors were encountered: