我想使用excel绘制图片,这是我的程序:
import numpy as np
import cv2
from openpyxl import Workbook
from openpyxl.utils import get_column_letter
from openpyxl.styles import PatternFill, Color, Font
b = cv2.imread('D:\DeepLearning\image\memeda2.png')
b = b[:, :, ::-1]
def rgb_to_hex(rgb):
return '%02x%02x%02x' % rgb
wb = Workbook()
ws = wb.active
for i in range(1, b.shape[0]+1):
for j in range(1, b.shape[1]+1):
ws.row_dimensions[i].height = 17.1
ws.column_dimensions[get_column_letter(j)].width = 3.0
ws['%s%s' % (get_column_letter(j), i)].fill = PatternFill(start_color=rgb_to_hex(tuple(b[i-1, j-1])), end_color=rgb_to_hex(tuple(b[i-1, j-1])), fill_type='solid')
wb.save('memeda2.xlsx')
对于一些图片,它运作良好,但冷杉其他它没有。我无法用正确的样式打开这些excel,通常它们没有着色。 对不起,我的英语很差,任何建议都可能有所帮助。