在openpyxl中为标签着色 [英] Coloring a tab in openpyxl

查看:198
本文介绍了在openpyxl中为标签着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们遇到一种情况,我们想使用openpyxl为工作表的选项卡上色.有没有办法在图书馆内做到这一点?或者,是否有人找到一种在库外部进行此操作的方法(即通过扩展或类似的方法)?

We have a situation where we want to color the tabs for the worksheets using openpyxl. Is there a way to do this within the library? Or, has anyone found a way to do this external to the library (i.e. by extension or something similar)?

推荐答案

您可以使用

You can set the tab color in a new Excel file using the XlsxWriter Python module. Here is an example:

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()

这篇关于在openpyxl中为标签着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆