Bouke / docx-mailmerge

Mail merge for Office Open XML (docx) files without the need for Microsoft Office Word.
MIT License
274 stars 104 forks source link

Cannot merge int #64

Closed huwcbjones closed 5 years ago

huwcbjones commented 5 years ago

Can't merge ints without wrapping each int in str()

Expected Behaviour

Library converts variable to string representation and merges that instead.

Current Behaviour

Library raises AttributeError when merging a type that is not a string.

Possible Solution

Possible fix in PR #65

Steps to Reproduce (for bugs)

doc = MailMerge("template.docx")
doc.merge(field=123)

Context

Trying to merge numerical types (ints/floats) without having to wrap each one in str(number)

Your Environment

mpapierski commented 5 years ago

@huwcbjones I faced similiar issue. You might want to try my fork of docx-mailmerge where you can pass any data type and it will get replaced correctly. Also, it supports attributes with spaces inside, a datetime type, which you can customize from within Word (i.e. MERGEFIELD "Date" \@ "dd/MM/yy" \* MERGEFORMAT), etc.