Home >Backend Development >Python Tutorial >Simple implementation of inserting pictures into Excel using Python
This article mainly introduces the simple implementation method of Python inserting pictures into Excel. It analyzes the related operation skills of Python using the XlsxWriter module to operate Excel cells and insert jpg format pictures based on examples. It is very simple and practical. Friends who need it can Refer to the following
The example of this article describes the simple implementation method of inserting pictures into Excel in Python. Share it with everyone for your reference, the details are as follows:
Use Python to insert pictures into Excel files. This function was implemented through the xlwt module when I was learning xlwt. It was an attempt at the company at that time. I have the impression that the inserted picture was eventually reduced to one cell. At the same time, due to the company's encryption system, the Excel file into which the picture was inserted could not be opened again.
This time I tried XlsxWriter
This module, it is speculated that this module should have much more powerful functions than xlwt. The code is implemented as follows:
#!/usr/bin/python # -*- codding: cp936 -*- import xlsxwriter book = xlsxwriter.Workbook('pict.xlsx') sheet = book.add_worksheet('demo') sheet.insert_image('D4','VCFY6863.jpg') book.close()
After the program is executed, an Excel file named pict.xlsx is generated. After opening, you can see that the picture is successfully inserted. The insertion point is the specified cell, and the upper left corner of the entire picture is in the specified cell. The general information is as follows:
#The insertion function is implemented, and it is also a relatively ideal insertion effect.
Related recommendations:
Python method of inserting data into a list
The above is the detailed content of Simple implementation of inserting pictures into Excel using Python. For more information, please follow other related articles on the PHP Chinese website!