import os
from openpyxl import Workbook
from openpyxl.drawing.image import Image
from win32com import client
导入方式 pip install pywin32 -i https://pypi.tuna.tsinghua.edu.cn/simple/
控制图片大小并将图片插入到excel单元格内
## 操作sheet
work_book = Workbook()
sheet = work_book.create_sheet(title="我的数据", index=0) # title就是sheet名
## 设置指定单元格的长与宽
column_width = 12.25
row_height = 80.10
sheet.column_dimensions['D'].width = column_width
sheet.row_dimensions[3].height = row_height
## 设置图片的长与宽
my_img = Image('./0fc62dc1d223455794c475c70f041737躯干.jpg')
newsize = (90, 90)
my_img.width, my_img.height = newsize # 这两个属性分别是对应添加图片的宽高
#保存数据
sheet.add_image(my_img, 'D3')
work_book.save("我的数据.xlsx")
将excel转化为PDF
[原作者文档] (https://vimsky.com/examples/usage/convert-excel-to-pdf-using-python.html)
## Open Microsoft Excel
excel = client.Dispatch("Excel.Application")
## Read Excel File
sheets = excel.Workbooks.Open('D:\pythontest\脚本处理\excel转化为pdf\我的数据.xlsx')
work_sheets = sheets.Worksheets[0]
## Convert into PDF File
work_sheets.ExportAsFixedFormat(0, 'D:\pythontest\脚本处理\excel转化为pdf\我的数据.pdf')