I want a logo file to be attached everytime in the word document, when I run the code,
Ideally the code should look like :
from docx import Document
document = Document()
logo = open('logo.eps', 'r') #the logo path that is to be attached
document.add_heading('Underground Heating Oil Tank Search Report', 0) #simple heading that will come bellow the logo in the header.
document.save('report for xyz.docx') #saving the file
is this possible in the python-docx or should i try some other library to do this? if possible please tell me how,
A simpler way to include logo and a header with some style (Heading 2 Char here):
from docx import Document
from docx.shared import Inches, Pt
doc = Document()
header = doc.sections[0].header
paragraph = header.paragraphs[0]
logo_run = paragraph.add_run()
logo_run.add_picture("logo.png", width=Inches(1))
text_run = paragraph.add_run()
text_run.text = '\t' + "My Awesome Header" # For center align of text
text_run.style = "Heading 2 Char"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With