简介
通过读取图片的各个像素的颜色,填充到excel单元格中
环境
- ubuntu 16.04 lts
- excel 2016
- python 2.7
- opvencv 3.1
目录结构
.
├── excel_image.py
├── test.jpg
└── test.xlsx
代码解析
import cv2
from string import uppercase as AtoZ
from openpyxl import load_workbook
from openpyxl.styles import PatternFill
# 读取图片
image = cv2.imread("test.jpg")
# 载入Excel
wb = load_workbook(filename='test.xlsx')
# 活动的sheet获取
ws = wb.active
# 字母列表生成
# col_name = ['A', 'B', ...., 'Z']
col_name = list(AtoZ)
# excel列名生成
for i in xrange(len(image[0]) - 26):
col_name.append(AtoZ[i // 26] + AtoZ[i % 26])
for col in xrange(len(image[0])):
# 列的宽度调整
ws.column_dimensions[col_name[col]].width = 0.3
for row in xrange(len(image)):
# 行的高度调整
ws.row_dimensions[row].height = 1.5
for col in xrange(len(image[row])):