本文整理汇总了Python中openpyxl.styles.Style方法的典型用法代码示例。如果您正苦于以下问题:Python styles.Style方法的具体用法?Python styles.Style怎么用?Python styles.Style使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openpyxl.styles
的用法示例。
在下文中一共展示了styles.Style方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_cell_style
# 需要导入模块: from openpyxl import styles [as 别名]
# 或者: from openpyxl.styles import Style [as 别名]
def get_cell_style(color='FF000000', bgcolor='FFFFFFFF', font='Calibri', size=11, bold=False, italic=False,
underline='none', strike=False, border=None, border_style=BORDER_THIN, border_bottom=None,
border_bottom_style=None, horizontal='general', vertical='bottom', number_format=None):
if not border:
border = 'FFB6B6B4'
if not border_bottom:
border_bottom = border
if not border_bottom_style:
border_bottom_style = border_style
return Style(font=Font(name=font, size=size, bold=bold, italic=italic, vertAlign=None, underline=underline,
strike=strike, color=color),
fill=PatternFill(patternType='solid', fgColor=Color(bgcolor)),
border=Border(
left=Side(border_style=border_style, color=Color(border)),
right=Side(border_style=border_style, color=Color(border)),
top=Side(border_style=border_style, color=Color(border)),
bottom=Side(border_style=border_bottom_style, color=Color(border_bottom)),),
alignment=Alignment(horizontal=horizontal, vertical=vertical, text_rotation=0, wrap_text=False,
shrink_to_fit=False, indent=0),
number_format=number_format
)
示例2: test_write_cells_merge_styled
# 需要导入模块: from openpyxl import styles [as 别名]
# 或者: from openpyxl.styles import Style [as 别名]
def test_write_cells_merge_styled(self):
from pandas.io.formats.excel import ExcelCell
from openpyxl import styles
sheet_name = 'merge_styled'
sty_b1 = {'font': {'color': '00FF0000'}}
sty_a2 = {'font': {'color': '0000FF00'}}
initial_cells = [
ExcelCell(col=1, row=0, val=42, style=sty_b1),
ExcelCell(col=0, row=1, val=99, style=sty_a2),
]
sty_merged = {'font': {'color': '000000FF', 'bold': True}}
sty_kwargs = _Openpyxl20Writer._convert_to_style_kwargs(sty_merged)
openpyxl_sty_merged = styles.Style(**sty_kwargs)
merge_cells = [
ExcelCell(col=0, row=0, val='pandas',
mergestart=1, mergeend=1, style=sty_merged),
]
with ensure_clean('.xlsx') as path:
writer = _Openpyxl20Writer(path)
writer.write_cells(initial_cells, sheet_name=sheet_name)
writer.write_cells(merge_cells, sheet_name=sheet_name)
wks = writer.sheets[sheet_name]
xcell_b1 = wks['B1']
xcell_a2 = wks['A2']
assert xcell_b1.style == openpyxl_sty_merged
assert xcell_a2.style == openpyxl_sty_merged