question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do i set table style

See original GitHub issue

Hi scanny.

How do i set table style?

When i using

document.add_table(rows=len(table_data), cols=len(table_data[0]),style="TableGrid")

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.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:3
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
scannycommented, Jan 20, 2014

What you need to do is open a document in your Document() call, not just use the default.

  1. Create a blank document in Word and save it as ‘template.docx’.
  2. Customize one of the table styles in ‘template.docx’ to look the way you want.
  3. Create a new table while still in Word, and apply the customized table style to it
  4. After that you can delete the table and save the file again.

After that you start a new document in python-docx using document = Document('template.docx') and it will use the file you customized. The table style you customized will be available to apply to tables you make with python-pptx. The table style name is the same as it is in Word, with all spaces removed. For example, ‘Light Shading - Accent 1’ becomes ‘LightShading-Accent1’.

3reactions
an1mehackercommented, Jan 2, 2020

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 Like this

document = Document() table.style = document.styles[‘Table Grid’]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change Table Style in Word
Click inside the table. · Click the Design tab in the Table Tools ribbon group. · (Optional) Click the Table Styles More button...
Read more >
How to Format Microsoft Word Tables Using Table Styles ...
Set a default table style · Click in the table. · Click the Table Tools Design or Table Design tab in the Ribbon....
Read more >
How To Style a Table with CSS
To begin, open styles.css in your text editor. The :nth-child() pseudo-class works by applying it to sibling elements. In this case, ...
Read more >
CSS Styling Tables
To specify table borders in CSS, use the border property. The example below specifies a solid border for <table>, <th>, and <td> elements:...
Read more >
Word 2013: Tables - GCF Global
To apply a table style: ... Click anywhere on the table, then click the Design tab on the right side of the Ribbon....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found