当前位置: 首页>>代码示例>>Python>>正文


Python styles.Style方法代码示例

本文整理汇总了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
                     ) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:23,代码来源:excel.py

示例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 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:34,代码来源:test_excel.py


注:本文中的openpyxl.styles.Style方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。