离岛
2020-07-09 09:37
已采纳
不太了解具体需求,提供一些示例代码和思路供你参考:
整体思路:首先已知excel中的颜色值,根据编码实现颜色筛选的功能
示例:
1、首先安装pip install openpyxl
2、示例代码可以获取Excel中指定背景填充色或文字颜色的数据(具体颜色值网上有很多在线rgb颜色转换的)
import openpyxl
filename = "colortest.xlsx" # 读取excel
workbook = openpyxl.load_workbook(filename)
worksheet = workbook.get_sheet_by_name("Sheet1") # 读取Sheet
rows, cols = worksheet.max_row, worksheet.max_column
reddata = []
yellowdata = []
for i in range(1, rows):
for j in range(1, cols):
ce = worksheet.cell(row=i, column=j)
fill = ce.fill
font = ce.font
# print(fill.start_color.rgb)
if fill.start_color.rgb == "FFEEFA50":
yellowdata.append(ce.value)
if fill.start_color.rgb == "FFFF1D1D":
reddata.append(ce.value)
# if font.color.rgb == "FFFF1D1D":
# reddata.append(ce.value)
print(yellowdata, reddata)