美文网首页
2020-11-11 识别图片,转换成excell

2020-11-11 识别图片,转换成excell

作者: 昨天今天下雨天1 | 来源:发表于2020-11-11 20:38 被阅读0次
from openpyxl import workbook
from openpyxl.utils import get_column_letter
from openpyxl.styles import PatternFill, Color
from PIL import Image

# 初始化
workbook = workbook.Workbook()
worksheet = workbook.active
im = Image.open("20200930123959.jpg")
im_width = im.size[0]
im_height = im.size[1]
pix = im.load()

# 根据照片大小循环
for row in range(1, im_height):
    for col in range(1, im_width):
        cell = worksheet.cell(column=col, row=row)
        pixpoint = pix[col - 1, row - 1]
        # 涂颜色
        pixColor = "FF%02X%02X%02X" % (pixpoint[0], pixpoint[1], pixpoint[2])
        fill = PatternFill(patternType='solid', fgColor=Color(rgb=pixColor))
        cell.fill = fill
    worksheet.row_dimensions[row].height = 6

for col in range(1, im_width):
    worksheet.column_dimensions[get_column_letter(col)].width = 1
workbook.save(filename='20200930123959.xlsx')

相关文章

网友评论

      本文标题:2020-11-11 识别图片,转换成excell

      本文链接:https://www.haomeiwen.com/subject/cfyybktx.html