Skip to content
This repository was archived by the owner on Jan 12, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def heading(headingtext, headinglevel, lang='en'):
return paragraph


def table(contents, heading=True, colw=None, cwunit='dxa', tblw=0, twunit='auto', borders={}, celstyle=None):
def table(contents, heading=True, colw=None, cwunit='dxa', tblw=0, twunit='auto', borders={}, celstyle=None, jc='left'):
"""
Return a table element based on specified parameters

Expand Down Expand Up @@ -312,6 +312,8 @@ def table(contents, heading=True, colw=None, cwunit='dxa', tblw=0, twunit='auto'
tableprops.append(tablestyle)
tablewidth = makeelement('tblW', attributes={'w': str(tblw), 'type': str(twunit)})
tableprops.append(tablewidth)
pJc = makeelement('jc', attributes={'val': jc})
tableprops.append(pJc)
if len(borders.keys()):
tableborders = makeelement('tblBorders')
for b in ['top', 'left', 'bottom', 'right', 'insideH', 'insideV']:
Expand Down Expand Up @@ -400,7 +402,7 @@ def table(contents, heading=True, colw=None, cwunit='dxa', tblw=0, twunit='auto'
return table


def picture(relationshiplist, picname, picdescription, pixelwidth=None, pixelheight=None, nochangeaspect=True, nochangearrowheads=True):
def picture(relationshiplist, picname, picdescription, pixelwidth=None, pixelheight=None, nochangeaspect=True, nochangearrowheads=True, jc='left'):
'''Take a relationshiplist, picture file name, and return a paragraph containing the image
and an updated relationshiplist'''
# http://openxmldeveloper.org/articles/462.aspx
Expand All @@ -409,7 +411,7 @@ def picture(relationshiplist, picname, picdescription, pixelwidth=None, pixelhei
# Copy the file into the media dir
media_dir = join(template_dir, 'word', 'media')
if not os.path.isdir(media_dir):
os.mkdir(media_dir)
os.makedirs(media_dir)
shutil.copyfile(picname, join(media_dir, picname))

# Check if the user has specified a size
Expand Down Expand Up @@ -501,6 +503,10 @@ def picture(relationshiplist, picname, picdescription, pixelwidth=None, pixelhei
run = makeelement('r')
run.append(drawing)
paragraph = makeelement('p')
pPr = makeelement('pPr')
pJc = makeelement('jc', attributes={'val': jc})
pPr.append(pJc)
paragraph.append(pPr)
paragraph.append(run)
return relationshiplist, paragraph

Expand Down