0

Using docxtpl library in Python to generate complex Microsoft Word documents from Excel data, is it possible to generate a single document from multiple "contexts" or tables?

For example, list1 contains people with data about each person, and list2 contains issues with data about each issue, and list3 contains data pertaining to relationships between the different people and different issues, and list4 contains data regarding the overall case.

Each table can have a varying and unlimited number of rows of data. And I want to have conditional statements and nested for loops through different tables at different points in the document to generate complex and dynamic paragraphs of text in the Word document.

How do you feed the "context" variable all that data from different tables of data? Examples I see online feed the "context" variable a single table.

Thank you for your help.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Rycliff
  • 127
  • 1
  • 9

1 Answers1

1

You can use the Open XML SDK for generating Word documents, see Welcome to the Open XML SDK 2.5 for Office for more information. As for Python, you may find the python-docx and python-ooxml libraries helpful.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Thank you Eugene Astafiev. I've abandoned docxtpl because of its limitations and moved to python-docx. I am a novice programmer, but I'm making progress using python-docx. Open XML SDK 2.5 for Office seems way more complicated. Can it be programmed using Python? Is is preferable to python-docx? I've got my hands full just trying to learn Python and am not looking to climb C# mountain. And VB is limited and antiquated. – Rycliff Dec 25 '22 at 07:47
  • I am originally a C# (VB) developer, not a Python. The Open XML SDK is a tool developed and supported by MS, so that is a pretty straightforward way of dealing with Office open XML documents. – Eugene Astafiev Dec 25 '22 at 16:42