Skip to content

Instantly share code, notes, and snippets.

@clementlefevre
Last active April 14, 2021 14:17
Show Gist options
  • Save clementlefevre/030ccbd8a936c812a9d510134cf6c6bf to your computer and use it in GitHub Desktop.
Save clementlefevre/030ccbd8a936c812a9d510134cf6c6bf to your computer and use it in GitHub Desktop.
# Add Logo
img = openpyxl.drawing.image.Image('logo.jpg')
p2e = pixels_to_EMU
h, w = img.height, img.width
size = XDRPositiveSize2D(p2e(w), p2e(h))
# Set image position on the top right of the Worksheet:
column = 8 # last column index (!!!starts from 0)
row = 0 # first row index (!!!starts from 0)
coloffset = -p2e(w) # we align the image with the right limit of the worksheet
marker = AnchorMarker(col=column, colOff=coloffset, row=row)
img.anchor = OneCellAnchor(_from=marker, ext=size)
ws.add_image(img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment