Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ def picture(relationshiplist, picname, picdescription, pixelwidth=None,
exif = image._getexif()
except:
exif = {}

if exif is None:
exif = {}

for tag, value in exif.items():
imageExif[TAGS.get(tag, tag)] = value
Expand Down
11 changes: 8 additions & 3 deletions example-makedocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

# Make a new document tree - this is the main part of a Word document
document = newdocument()

# Make a dict in which you will store image data
imagefiledict = {}

# This xpath location is where most interesting content lives
body = document.xpath('/w:document/w:body', namespaces=nsprefixes)[0]
Expand Down Expand Up @@ -67,8 +70,9 @@
body.append(paragraph(point, style='ListBullet'))

# Add an image
relationships, picpara = picture(relationships, 'image1.png',
'This is a test description')
relationships, picpara, imagefiledict = picture(relationships, 'image1.png',
'This is a test description',
imagefiledict=imagefiledict)
body.append(picpara)

# Search and replace
Expand Down Expand Up @@ -109,5 +113,6 @@

# Save our document
savedocx(document, coreprops, appprops, contenttypes, websettings,
wordrelationships, 'Welcome to the Python docx module.docx')
wordrelationships, 'Welcome to the Python docx module.docx'
imagefiledict=imagefiledict)