Paste the image into an excel file using Python's openpyxl

Paste the image to fit the default cell size

Paste the image in the range of A1 to 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)

Paste the image in the range of K3 to 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)

Paste the image in the range of C13 to 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, 'K3')
workbook.save(insert.xlsx)

image.png

Reference URL

https://allabout.co.jp/gm/gc/297706/ https://qiita.com/HirotakaKikushima/items/a42e3e94273247199b9a

Recommended Posts

Paste the image into an excel file using Python's openpyxl
How to paste a CSV file into an Excel file using Pandas
Create an image file using PIL (Python Imaging Library).
[Python] Mask the image into a circle using Pillow
Try to operate an Excel file using Python (Pandas / XlsxWriter) ①
Try to operate an Excel file using Python (Pandas / XlsxWriter) ②
Manipulate the clipboard in Python and paste the table into Excel
Understand the function of convolution using image processing as an example
Excel file column addition and row deletion processing using Python Openpyxl
Get the formula in an excel file as a string in Python
Create an Excel file with Python3
Paste the matplotlib figure on excel
Extract the targz file using python
Get the file path using Pathlib
[Python] [Excel] Operate an Excel sheet from Python using openpyxl (using a test sheet as an example)
Open an Excel file in Python and color the map of Japan
Download the file from S3 using boto.
Try using the camera with Python's OpenCV
[GIMP] [Python-Fu] Divide the image into swords
Create an application using the Spotify API
Execute the COPY command using python's Psycopg
Feel free to turn Python using the library into an AWS Lambda function
Save an array of numpy to a wav file using the wave module