python-openxml / python-docx

Create and modify Word documents with Python
MIT License
4.54k stars 1.11k forks source link

Multiple tables data inserting issue #1345

Closed varathagithub closed 5 months ago

varathagithub commented 7 months ago

we have to create the multiple tables in the template Docx , for that we used the jinja text which is mentioned below

{% for _ in range(CONFIG) %}

Business Operation Name:    {{ob}}
{%tc for ip in IPADDRESS %} {{ ip }}    {%tc endfor %}

{% endfor %}

it is created as expected but we need to push the appropriate value into the table. Here we are facing the issue is consider we have two table , expectation:two table should have different value but the latest value is placed into the two table which means same value. here is my code

from docxtpl import DocxTemplate
import json
doc = DocxTemplate("C:\\InterSystems\\IRISHealth\\Ais\\Sample_Yard\\demo.docx")
context1={}
context={}
count=0
context['CONFIG']=2
context1={
'IPADDRESS':['IP Address','{{IPADDRESS1}}','The Address of the Target System'],
'PORT':['PORT','{{PORT1}}','The Port number of the target'],
'StayConnected':['Stay Connected','{{Stayconnected1}}','The default value of -1 means to stay permanently connected, even during idle times, and treats adisconnection as an error. Any positive integer determines the number of seconds to be connected for']
}
context.update(context1)
doc.render(context)
context2={
'IPADDRESS':['IP Address1','{{IPADDRESS2}}','The Address of the Target System'],
'PORT':['PORT1','{{PORT2}}','The Port number of the target'],
'StayConnected':['Stay Connected1','{{Stayconnected2}}','The default value of -1 means to stay permanently connected, even during idle times, and treats adisconnection as an error. Any positive integer determines the number of seconds to be connected for']
}
context.update(context2)
doc.render(context)
#context['CONFIG']=2
doc.save("C:\\InterSystems\\IRISHealth\\AISTEST\\configoutput13.docx")
scanny commented 5 months ago

@varathagithub python-docx-template is a different project, not directly associated with python-docx. You'll need to ask this question on their issues list :) https://github.com/elapouya/python-docx-template/issues