How to use the openpyxl.styles.Side function in openpyxl

To help you get started, we’ve selected a few openpyxl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mitre-attack / attack-scripts / layers / exporters / excel_templates.py View on Github external
:param showID: Whether or not to display Technique IDs for each entry
            :param sort: The sort mode to use
            :param subtechs: List of all visible subtechniques
            :param exclude: List of of techniques to exclude from the matrix
            :return: a openpyxl workbook object containing the raw matrix
        """
        self.codex = self.h._adjust_ordering(self.codex, sort, scores)
        template, joins = self.h._construct_panop(self.codex, subtechs, exclude)
        self.template = template
        wb = openpyxl.Workbook()

        sheet = wb.active

        header_template_f = Font(name='Calibri', bold=True)
        header_template_a = Alignment(horizontal='center', vertical='bottom')
        header_template_b = Border(bottom=Side(border_style='thin'))
        header_template_c = PatternFill(patternType='solid', start_color='DDDDDD', end_color='DDDDDD')

        for entry in template:
            c = sheet.cell(row=entry[0], column=entry[1])
            write_val = ''
            if showName and showID:
                write_val = self.h._get_ID(self.codex, template[entry]) + ': ' + template[entry]
            elif showName:
                write_val = template[entry]
            elif showID:
                write_val = self.h._get_ID(self.codex, template[entry])
            c.value = write_val
            if entry[0] == 1:
                c.font = header_template_f
                c.alignment = header_template_a
                c.border = header_template_b
github SverkerSbrg / openpyxl-templates / openpyxl_templates / utils.py View on Github external
def ColoredBorders(color, top=True, right=True, bottom=True, left=True):
    color = _color(color)
    return Border(
        top=Side(style=BORDER_MEDIUM, color=color) if top else None,
        right=Side(style=BORDER_MEDIUM, color=color) if right else None,
        bottom=Side(style=BORDER_MEDIUM, color=color) if bottom else None,
        left=Side(style=BORDER_MEDIUM, color=color) if left else None,
    )
github pandas-dev / pandas / pandas / io / excel / _openpyxl.py View on Github external
A string specifying the border style, or a dict with zero or more
            of the following keys (or their synonyms).
                'style' ('border_style')
                'color'

        Returns
        -------
        side : openpyxl.styles.Side
        """

        from openpyxl.styles import Side

        _side_key_map = {"border_style": "style"}

        if isinstance(side_spec, str):
            return Side(style=side_spec)

        side_kwargs = {}
        for k, v in side_spec.items():
            if k in _side_key_map:
                k = _side_key_map[k]
            if k == "color":
                v = cls._convert_to_color(v)
            side_kwargs[k] = v

        return Side(**side_kwargs)
github yidao620c / core-python / samples / excel / mysql_to_excel2.py View on Github external
def export_to_excel(db_data, xlsx_name):
    """导出到excel文件中"""
    _log.info('开始导出到excel文件中')
    border = Border(
        left=Side(border_style=borders.BORDER_THIN, color='FF000000'),
        right=Side(border_style=borders.BORDER_THIN, color='FF000000'),
        top=Side(border_style=borders.BORDER_THIN, color='FF000000'),
        bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')
    )
    alignment = Alignment(horizontal='justify',
                          vertical='bottom',
                          text_rotation=0,
                          wrap_text=False,
                          shrink_to_fit=True,
                          indent=0)
    fill = PatternFill(fill_type=None, start_color='FFFFFFFF')
    # 基本的样式
    basic_style = Style(font=Font(name='Microsoft YaHei')
                        , border=border, alignment=alignment
                        , fill=fill)
    # header_style = basic_style.copy(
github yidao620c / core-python / samples / excel / generate_schema.py View on Github external
def write_dest(xlsx_name, schema_name):
    border = Border(
        left=Side(border_style=borders.BORDER_THIN, color='FF000000'),
        right=Side(border_style=borders.BORDER_THIN, color='FF000000'),
        top=Side(border_style=borders.BORDER_THIN, color='FF000000'),
        bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')
    )
    alignment = Alignment(horizontal='justify', vertical='bottom',
                          text_rotation=0, wrap_text=False,
                          shrink_to_fit=True, indent=0)
    fill = PatternFill(fill_type=None, start_color='FFFFFFFF')
    # 基本的样式
    basic_style = NamedStyle(name="basic_style", font=Font(name='Microsoft YaHei')
                             , border=border, alignment=alignment, fill=fill)
    title_style = copy(basic_style)
    title_style.name = 'title_style'
    title_style.font = Font(name='Microsoft YaHei', b=True, size=20, color='00215757')
    title_style.alignment = Alignment(horizontal='center', vertical='bottom',
                                      text_rotation=0, wrap_text=False,
                                      shrink_to_fit=True, indent=0)
    title_style.fill = PatternFill(fill_type=fills.FILL_SOLID, start_color='00B2CBED')
github wharton / drf-renderer-xlsx / drf_renderer_xlsx / renderers.py View on Github external
}
    :param style_name: name of created style
    :return: openpyxl.styles.NamedStyle instance
    """
    style = NamedStyle(name=style_name)
    if not style_dict:
        return style
    for key, value in style_dict.items():
        if key == "font":
            style.font = Font(**value)
        elif key == "fill":
            style.fill = PatternFill(**value)
        elif key == "alignment":
            style.alignment = Alignment(**value)
        elif key == "border_side":
            side = Side(**value)
            style.border = Border(left=side, right=side, top=side, bottom=side)

    return style

github CarlKing5019 / python3-cookbook-personal / basic / samples / excel / generate_schema.py View on Github external
def write_dest(xlsx_name, schema_name):
    border = Border(
        left=Side(border_style=borders.BORDER_THIN, color='FF000000'),
        right=Side(border_style=borders.BORDER_THIN, color='FF000000'),
        top=Side(border_style=borders.BORDER_THIN, color='FF000000'),
        bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')
    )
    alignment = Alignment(horizontal='justify', vertical='bottom',
                          text_rotation=0, wrap_text=False,
                          shrink_to_fit=True, indent=0)
    fill = PatternFill(fill_type=None, start_color='FFFFFFFF')
    # 基本的样式
    basic_style = Style(font=Font(name='Microsoft YaHei')
                        , border=border, alignment=alignment
                        , fill=fill)
    title_style = basic_style.copy(
        font=Font(name='Microsoft YaHei', b=True, size=20, color='00215757'),
        alignment=Alignment(horizontal='center', vertical='bottom',
                            text_rotation=0, wrap_text=False,
                            shrink_to_fit=True, indent=0),
github InvestmentSystems / table-compositor / table_compositor / xlsx_styles.py View on Github external
class OpenPyxlStyleHelper:

    # good reference:
    # https://www.ozgrid.com/Excel/excel-custom-number-formats.htm
    DOLLAR_FORMAT = '_($* #,##0_);_($* (#,##0);_($* "-"??_);_(@_)'
    CENTS_FORMAT = '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)'

    # without dollar sign, but has same rendering format for currency
    GENERAL_CURRENCY_FORMAT = '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)'
    PERCENT_FORMAT = '0.00%'

    class CustomBorders:
        thin_white = Side(border_style='thin', color='FFFFFF')
        thick_white = Side(border_style='thick', color='FFFFFF')

        thin_black = Side(border_style='thin', color='000000')
        thick_black = Side(border_style='thick', color='000000')

        border = Border(left=thin_white, right=thin_white,
                top=thin_white, bottom=thin_white)
        left_border = Border(left=thick_white, right=thin_white,
                top=thin_white, bottom=thin_white)
        right_border = Border(
            left=thin_white, right=thick_white,
            top=thin_white, bottom=thin_white)

        top_right_border = Border(left=thin_white, right=thin_black,
                top=thin_black, bottom=thin_white)
        top_left_border = Border(left=thin_white, right=thin_black,
                top=thin_black, bottom=thin_white)

        top_border = Border(left=thin_white, right=thin_white,
github Talengi / phase / src / distriblists / utils.py View on Github external
from accounts.models import User
from distriblists.models import DistributionList
from distriblists.forms import DistributionListForm


header_alignment = Alignment(
    horizontal='center',
    textRotation=45,
)

role_alignment = Alignment(
    horizontal='center'
)
cell_border = Border(
    top=Side(style='thin'),
    bottom=Side(style='thin'),
    left=Side(style='thin'),
    right=Side(style='thin'),
    vertical=Side(style='thin')
)


def import_review_members(filepath, category):
    """Import review members from an excel file."""
    wb = openpyxl.load_workbook(filepath)
    ws = wb.active

    # Extracts the user list from the header row
    emails, user_ids = _extract_users(ws)

    max_col = len(user_ids) + 1  # Don't use ws.max_column, it's not reliable