我们希望使用openpyxl为工作表的标签着色。有没有办法在图书馆内这样做?或者,是否有人找到了在库外部执行此操作的方法(即通过扩展或类似的东西)?
答案 0 :(得分:6)
您可以使用对于sheet_properties.tabColor属性的RRGGBB颜色代码,使用openpyxl为选项卡着色:
from openpyxl import Workbook
wb = Workbook()
ws = wb.create_sheet('My_Color_Title')
ws.sheet_properties.tabColor = 'FFFF00'
wb.save('My_book_with_Yellow_Tab.xlsx')
答案 1 :(得分:3)
您可以使用XlsxWriter Python模块在新的Excel文件中设置标签颜色。这是一个例子:
from xlsxwriter.workbook import Workbook
workbook = Workbook('tab_colors.xlsx')
# Set up some worksheets.
worksheet1 = workbook.add_worksheet()
worksheet2 = workbook.add_worksheet()
worksheet3 = workbook.add_worksheet()
worksheet4 = workbook.add_worksheet()
# Set tab colours
worksheet1.set_tab_color('red')
worksheet2.set_tab_color('green')
worksheet3.set_tab_color('#FF9900') # Orange
# worksheet4 will have the default colour.
workbook.close()