diff --git a/docx.py b/docx.py index 3ab37bb..ad98766 100755 --- a/docx.py +++ b/docx.py @@ -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 @@ -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']: @@ -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 @@ -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 @@ -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