Merge pull request #124 from isaacsucn/master

Insert exist document as subdocument
This commit is contained in:
Eric Lapouyade 2018-06-21 12:16:40 +02:00 committed by GitHub
commit 76345f454f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -199,8 +199,8 @@ class DocxTemplate(object):
etree.SubElement(tblGrid, ns+'gridCol', {ns+'w': str(int(new_average))}) etree.SubElement(tblGrid, ns+'gridCol', {ns+'w': str(int(new_average))})
return tree return tree
def new_subdoc(self): def new_subdoc(self,docpath=None):
return Subdoc(self) return Subdoc(self,docpath)
@staticmethod @staticmethod
def get_file_crc(filename): def get_file_crc(filename):
@ -349,10 +349,10 @@ class DocxTemplate(object):
class Subdoc(object): class Subdoc(object):
""" Class for subdocument to insert into master document """ """ Class for subdocument to insert into master document """
def __init__(self, tpl): def __init__(self, tpl,docpath=None):
self.tpl = tpl self.tpl = tpl
self.docx = tpl.get_docx() self.docx = tpl.get_docx()
self.subdocx = Document() self.subdocx = Document(docpath)
self.subdocx._part = self.docx._part self.subdocx._part = self.docx._part
def __getattr__(self, name) : def __getattr__(self, name) :