better subdoc management : accept tables
This commit is contained in:
parent
755b7ae050
commit
e7a9291723
@ -1,3 +1,7 @@
|
|||||||
|
0.1.9 (2016-1-18)
|
||||||
|
-----------------
|
||||||
|
- better subdoc management : accept tables
|
||||||
|
|
||||||
0.1.8 (2015-11-05)
|
0.1.8 (2015-11-05)
|
||||||
------------------
|
------------------
|
||||||
- better xml code cleaning around Jinja2 tags
|
- better xml code cleaning around Jinja2 tags
|
||||||
|
|||||||
@ -5,7 +5,7 @@ Created : 2015-03-12
|
|||||||
@author: Eric Lapouyade
|
@author: Eric Lapouyade
|
||||||
'''
|
'''
|
||||||
|
|
||||||
__version__ = '0.1.8'
|
__version__ = '0.1.9'
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from docx import Document
|
from docx import Document
|
||||||
@ -95,9 +95,7 @@ class Subdoc(object):
|
|||||||
return getattr(self.subdocx, name)
|
return getattr(self.subdocx, name)
|
||||||
|
|
||||||
def _get_xml(self):
|
def _get_xml(self):
|
||||||
xml = ''
|
xml = re.sub(r'</?w:body[^>]*>','',etree.tostring(self.subdocx._element.body, encoding='unicode', pretty_print=False))
|
||||||
for p in self.paragraphs:
|
|
||||||
xml += '<w:p>\n' + re.sub(r'^.*\n', '', etree.tostring(p._element, encoding='unicode', pretty_print=True))
|
|
||||||
return xml
|
return xml
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
|
|||||||
BIN
tests/python_logo.png
Normal file
BIN
tests/python_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
@ -6,6 +6,7 @@ Created : 2015-03-12
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
from docxtpl import DocxTemplate
|
from docxtpl import DocxTemplate
|
||||||
|
from docx.shared import Inches
|
||||||
|
|
||||||
tpl=DocxTemplate('test_files/subdoc_tpl.docx')
|
tpl=DocxTemplate('test_files/subdoc_tpl.docx')
|
||||||
|
|
||||||
@ -17,6 +18,27 @@ p.add_run(' generated with python by using ')
|
|||||||
p.add_run('python-docx').italic = True
|
p.add_run('python-docx').italic = True
|
||||||
p.add_run(' library')
|
p.add_run(' library')
|
||||||
|
|
||||||
|
sd.add_heading('Heading, level 1', level=1)
|
||||||
|
sd.add_paragraph('This is an Intense quote', style='IntenseQuote')
|
||||||
|
|
||||||
|
sd.add_paragraph('A picture :')
|
||||||
|
sd.add_picture('python_logo.png', width=Inches(1.25))
|
||||||
|
|
||||||
|
sd.add_paragraph('A Table :')
|
||||||
|
table = sd.add_table(rows=1, cols=3)
|
||||||
|
hdr_cells = table.rows[0].cells
|
||||||
|
hdr_cells[0].text = 'Qty'
|
||||||
|
hdr_cells[1].text = 'Id'
|
||||||
|
hdr_cells[2].text = 'Desc'
|
||||||
|
recordset=( (1,101,'Spam'),
|
||||||
|
(2,42,'Eggs'),
|
||||||
|
(3,631,'Spam,spam, eggs, and ham') )
|
||||||
|
for item in recordset:
|
||||||
|
row_cells = table.add_row().cells
|
||||||
|
row_cells[0].text = str(item[0])
|
||||||
|
row_cells[1].text = str(item[1])
|
||||||
|
row_cells[2].text = item[2]
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'mysubdoc' : sd,
|
'mysubdoc' : sd,
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user