5
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Pythonのopenpyxlを使って画像をエクセルファイルに張り付ける

Last updated at Posted at 2020-07-18

##画像をデフォルトのセルサイズに合わせて張り付ける
画像をA1~G10の範囲に張り付ける。

import openpyxl


workbook = openpyxl.load_workbook('insert.xlsx')
sheet = workbook['Sheet1']
img = openpyxl.drawing.image.Image('img.png')
img.width = 72 * 7
img.height = 25 * 10
sheet.add_image(img, 'A1')
workbook.save('insert.xlsx')

画像をK3~T15の範囲に張り付ける。

workbook = openpyxl.load_workbook('insert.xlsx')
sheet = workbook['Sheet1']
img = openpyxl.drawing.image.Image('img.png')
img.width = 72 * 10
img.height = 25 * 13
sheet.add_image(img, 'K3')
workbook.save('insert.xlsx')

画像をC13~D21の範囲に張り付ける。

workbook = openpyxl.load_workbook('insert.xlsx')
sheet = workbook['Sheet1']
img = openpyxl.drawing.image.Image('img.png')
img.width = 72 * 2
img.height = 25 * 9
sheet.add_image(img, 'C13')
workbook.save('insert.xlsx')

image.png

##参考URL
https://allabout.co.jp/gm/gc/297706/
https://qiita.com/HirotakaKikushima/items/a42e3e94273247199b9a

5
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?