马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
为什么我运行下面代码会报错:# -*- coding: utf-8 -*-
import openpyxl
from openpyxl.styles import PatternFill
orange = PatternFill(fill_type=None, start_color='#FFA100')
wb = openpyxl.load_workbook(filename="计划表.xlsx")
ws = wb.active
ws.title = "计划表"
ws["A1"].fill = orange
报错内容:Traceback (most recent call last):
File "D:/files/Aaron/编程/code/python/PycharmProjects/计划表管理/main.py", line 6, in <module>
orange = PatternFill(fill_type=None, start_color=(0, 255, 161, 0))
File "D:\files\Aaron\编程\code\python\PycharmProjects\计划表管理\venv\lib\site-packages\openpyxl\styles\fills.py", line 91, in __init__
self.fgColor = fgColor
File "D:\files\Aaron\编程\code\python\PycharmProjects\计划表管理\venv\lib\site-packages\openpyxl\styles\colors.py", line 134, in __set__
super(ColorDescriptor, self).__set__(instance, value)
File "D:\files\Aaron\编程\code\python\PycharmProjects\计划表管理\venv\lib\site-packages\openpyxl\descriptors\base.py", line 42, in __set__
raise TypeError('expected ' + str(self.expected_type))
TypeError: expected <class 'openpyxl.styles.colors.Color'>
Process finished with exit code 1
和你这个fill_type有关吧,而且最后要保存 # -*- coding: utf-8 -*-
import openpyxl
from openpyxl.styles import PatternFill
orange = PatternFill(fill_type="solid", start_color='DC143C')
wb = openpyxl.load_workbook(filename="1.xlsx")
ws = wb.active
#ws.title = "计划表"
ws["B1"].fill = orange
ws['B1'].value='1'
wb.save("1.xlsx")
|