Talk is cheap. Show me the code.
代码如下:
修改生成的Excel的sheet名字为1,并在内部新建sheet命名为2。
import numpy as np
from PIL import Image
import openpyxl
date_sub=Image.open("photo-path") #替换为对应图片绝对路径
x,y=date_sub.size
data=np.array(date_sub.getdata()).reshape((y,x,3))
f=openpyxl.Workbook()
sheet_1=f.active
sheet_1.title='1'
for (a,b) in enumerate(data):
for (c,d) in enumerate(b):
sheet_1.cell(row=a+1,column=c+1,value=(str(d[0])+"-"+str(d[1])+"-"+str(d[2])))
f.save('Niejvv.xlsx') #替换为EXCEL路径
#EXCEL vba代码
"""
Sub 按RGB值显示颜色()
Dim str
For r = 1 To Worksheets("1").UsedRange.Rows.Count
For c = 1 To Worksheets("1").UsedRange.Columns.Count
str = Worksheets("1").Cells(r, c).Value
Worksheets("2").Cells(r, c).Interior.Color = RGB(Split(str, "-")(0), Split(str, "-")(1), Split(str, "-")(2))
Next
Next
End Sub
"""
https://www.bilibili.com/video/BV1J441147Ht/
B站这个视频也是我的,喜欢的请B站也关注我一下。