From 871dd85d49556b03a9ce3e948996d3c5581c9131 Mon Sep 17 00:00:00 2001 From: isaacsucn Date: Thu, 21 Jun 2018 17:57:42 +0800 Subject: [PATCH] Inset exist document as subdocument --- docxtpl/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docxtpl/__init__.py b/docxtpl/__init__.py index fa1bd35..886c89f 100644 --- a/docxtpl/__init__.py +++ b/docxtpl/__init__.py @@ -199,8 +199,8 @@ class DocxTemplate(object): etree.SubElement(tblGrid, ns+'gridCol', {ns+'w': str(int(new_average))}) return tree - def new_subdoc(self): - return Subdoc(self) + def new_subdoc(self,docpath=None): + return Subdoc(self,docpath) @staticmethod def get_file_crc(filename): @@ -349,10 +349,10 @@ class DocxTemplate(object): class Subdoc(object): """ Class for subdocument to insert into master document """ - def __init__(self, tpl): + def __init__(self, tpl,docpath=None): self.tpl = tpl self.docx = tpl.get_docx() - self.subdocx = Document() + self.subdocx = Document(docpath) self.subdocx._part = self.docx._part def __getattr__(self, name) :