Search code examples
pythonpython-docx

Change table length in word-document, python-docx, Python


I can't seem to find a way to change the length f the entire table in a word-document. I have only seen examples of ways to change the columns in the table, not the actual table itself.

Would be great if someone could tell me how to do it :)

Here is my code:

from docx import Document
document = Document()
table = document.add_table(rows=4, cols=2)
table.style = 'Table Grid'

Solution

  • Found a solution to my problem. I got this from ANOTHER user here @ stack. Can't seem to find the link tho....

    The original code is NOT mine, I only modified it a little.

    def ChangeWidthOfTable(table,width,column):
      for columnVarible in range(0,column):
          for cell in table.columns[columnVarible].cells:
              cell.width = Cm(width)