How to use the openpyxl.styles.PatternFill 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 wind39 / spartacus / tests / test_report.py View on Github external
# )

    v_boldFont = openpyxl.styles.Font(bold=True)

    v_centerAlignment = openpyxl.styles.Alignment(
        horizontal="center", vertical="center", wrapText=True
    )

    v_workSheet.merge_cells("A2:F2")
    v_workSheet["A2"] = bs4.BeautifulSoup(v_reportName, "lxml").get_text()
    v_workSheet["A2"].font = v_boldFont
    v_workSheet["A2"].alignment = v_centerAlignment

    v_headerFont = openpyxl.styles.Font(bold=True)

    v_headerFill = openpyxl.styles.PatternFill("solid", fgColor="DBE5F1")

    v_headerAlignment = openpyxl.styles.Alignment(
        horizontal="center", vertical="center", wrapText=True
    )

    v_numberAlignment = openpyxl.styles.Alignment(
        horizontal="right", vertical="center", wrapText=True
    )

    v_textAlignment = openpyxl.styles.Alignment(
        horizontal="left", vertical="center", wrapText=True
    )

    v_dateAlignment = openpyxl.styles.Alignment(
        horizontal="center", vertical="center", wrapText=True
    )
github fez09 / FPL-data-scraper / FPLDataFetcher.py View on Github external
while chip == '3xc':
                for key in gwh_col:
                    wc = sheet1.cell(row=chipgw + 1, column=key)
                    wc.fill = triplecapfill
                break

        ## Import weekly team player data and points
        gwteamheaderow = 41
        gwtitle = 3
        for gw in range(1, 39):
            sheet1.cell(row=gwteamheaderow, column=gwtitle).value = str('GW {}'.format(gw))
            sheet1.cell(row=gwteamheaderow, column=gwtitle + 1).value = str('P {}'.format(gw))
            gwtitle = gwtitle + 2
        capfill = PatternFill(start_color='ff15dd43', end_color='ff15dd43', fill_type='solid')
        vcapfill = PatternFill(start_color='ff00FFDA', end_color='ff00FFDA', fill_type='solid')
        benchfill = PatternFill(start_color='ffBA6B12', end_color='ffBA6B12', fill_type='solid')
        for rownum in range(53, 57):
            for colnum in range(3, 79):
                bench = sheet1.cell(row=rownum, column=colnum)
                bench.fill = benchfill

        gwteamcol = (39 * 2 - int(num_of_gw * 2)) - 1  # To accomodate for people who started late.
        capfont = Font(underline='single')
        for each in json_history['history']:
            g_w = each['event']
            url3 = 'https://fantasy.premierleague.com/drf/entry/{}/event/{}/picks'.format(self.fpl_prompt.get(), g_w)
            json_pick = requests.get(url3).json()
            gwteamcol = gwteamcol + 2
            gwteamrow = 42
            url4 = 'https://fantasy.premierleague.com/drf/event/{}/live'.format(g_w)
            json_points = requests.get(url4).json()
            total_players = len(json_points['elements'])
github appcell / OverwatchDataAnalysis / python / ora / excel / __init__.py View on Github external
def _setting_cell_color(self):
        color = self.config['style']['color']
        for k, v in color.items():
            self.sheet[k].fill = PatternFill(
                fill_type='solid',
                fgColor=v,
            )
github fez09 / FPL-data-scraper / FPLDataScraper.py View on Github external
sheet1.cell(row=rownum, column=6).value = h_p

        ## Import all player data in premier league
        d = {}
        for each in json_live['elements']:
            pl_position = each['element_type']
            pl_id = each['id']
            pl_name = each['web_name']
            d[pl_id] = pl_name
        tot_player = len(d)

        ## Select data for Chip usage and enter in GW history as highlights
        wildcardfill = PatternFill(start_color='ffff0000', end_color='ffff0000', fill_type='solid')
        freehitfill = PatternFill(start_color='ffff00ff', end_color='ffff00ff', fill_type='solid')
        bboostfill = PatternFill(start_color='ffffa500', end_color='ffffa500', fill_type='solid')
        triplecapfill = PatternFill(start_color='ff0099ff', end_color='ff0099ff', fill_type='solid')
        gwh_col = range(1, 13)
        for each in json_history['chips']:
            chipgw = each['event']
            chip = each['name']
            while chip == 'wildcard':
                for key in gwh_col:
                    wc = sheet1.cell(row=chipgw + 1, column=key + 2)
                    wc.fill = wildcardfill
                break
            while chip == 'bboost':
                for key in gwh_col:
                    wc = sheet1.cell(row=chipgw + 1, column=key + 2)
                    wc.fill = bboostfill
                break
            while chip == 'freehit':
                for key in gwh_col:
github actionml / ur-analysis-tools / excel.py View on Github external
def create_table(ws, column_names, columns, title=None, bold_first_column=True, selected_rows=None, selected_columns=None):
    if selected_rows is None:
        selected_rows = []

    if selected_columns is None:
        selected_columns = []

    bold_ft = Font(bold=True)
    fill = PatternFill(fill_type='solid',
                       start_color='FF27E85B',
                       end_color='FF27E85B')

    #prepare data
    formated_columns = []
    for column in columns:
        formated_column = []
        for value in column:
            if isinstance(value, int):
                formated_column.append("{:,}".format(value))
            elif isinstance(value, float):
                formated_column.append("%.4f" % value)
            else:
                formated_column.append(value)
        formated_columns.append(formated_column)
github limodou / uliweb / uliweb / utils / xltools.py View on Github external
def _format_header_cell(self, cell, start_column, start_row, end_column, end_row):
        from openpyxl.styles import PatternFill, Border, Side, Alignment, Protection, Font

        align = Alignment(horizontal='center', vertical='center')
        fill = PatternFill(start_color=self.header_color,
               end_color=self.header_color,
               fill_type='solid')
        border = Border(left=Side(border_style='thin',
                       color=self.border_color),
             right=Side(border_style='thin',
                        color=self.border_color),
             top=Side(border_style='thin',
                      color=self.border_color),
             bottom=Side(border_style='thin',
                         color=self.border_color))

        self._style_range(cell,
                    get_range_string(start_column, start_row, end_column, end_row),
                    border=border, fill=fill, alignment=align)
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')
    header_style = copy(basic_style)
    header_style.name='header_style'
    header_style.font = Font(name='Microsoft YaHei', b=True, size=15, color='00215757')
    header_style.fill = PatternFill(fill_type=fills.FILL_SOLID, start_color='00BAA87F')
    common_style = copy(basic_style)
    common_style.name = 'common_style'
github bluecatlabs / gateway-workflows / Community / zone_exporter / exporter.py View on Github external
return os.path.dirname(os.path.abspath(__file__))

def get_resource_text():
    return util.get_text(module_path(), config.language)


r_text= get_resource_text()
SHEET_TITLE_FOR_CONFIGURATION = r_text['sheet_title_for_configuration']
SHEET_TITLE_FOR_VIEW = r_text['sheet_title_for_view']
SHEET_TITLE_FOR_ZONE = r_text['sheet_title_for_zone']
SHEET_TITLE_FOR_STRUCTURE = r_text['sheet_title_for_structure']

BOLD_FONT = Font(bold=True)
LINK_FONT = Font(underline='single', color=Color(theme=10, type="theme"))
BOLD_LINK_FONT = Font(bold=True, underline='single', color=Color(theme=10, type="theme"))
TITLE_FILL_COLOR = PatternFill('solid', fgColor='9BC2E6')

def load_config(module_dir, nodes):
    global col_config
    col_config = json.load(open(CONFIG_FILE % (module_dir, config.language)))
    for col in col_config['zone']:
        node = {}
        node['label'] = col['title']
        node['name'] = col['id']
        node['index'] = col['id']
        node['width'] = col['gwidth']
        node['sortable'] = False
        nodes.append(node)

def set_common_props(node, parent, level, entity):
    node['id'] = entity.get_id()
    node['parent'] = parent
github fez09 / FPL-data-scraper / FPLDataFetcher.py View on Github external
for rownum in range(g_w + 1, g_w + 2):
                sheet1.cell(row=rownum, column=6).value = h_p

        ## Import all football players' data in premier league
        player_d = {}
        for each in json_live['elements']:
            pl_position = each['element_type']
            pl_id = each['id']
            pl_name = each['web_name']
            player_d[pl_id] = pl_name
        tot_player = len(player_d)

        ## Select data for Chip usage and enter in GW history as highlights
        wildcardfill = PatternFill(start_color='ffff0000', end_color='ffff0000', fill_type='solid')
        freehitfill = PatternFill(start_color='ffff00ff', end_color='ffff00ff', fill_type='solid')
        bboostfill = PatternFill(start_color='ffffa500', end_color='ffffa500', fill_type='solid')
        triplecapfill = PatternFill(start_color='ff0099ff', end_color='ff0099ff', fill_type='solid')
        gwh_col = range(3, 17)
        for each in json_history['chips']:
            chipgw = each['event']
            chip = each['name']
            while chip == 'wildcard':
                for key in gwh_col:
                    wc = sheet1.cell(row=chipgw + 1, column=key)
                    wc.fill = wildcardfill
                break
            while chip == 'bboost':
                for key in gwh_col:
                    wc = sheet1.cell(row=chipgw + 1, column=key)
                    wc.fill = bboostfill
                break
            while chip == 'freehit':
github dimagi / commcare-hq / custom / abt / reports / views.py View on Github external
    @property
    def excel_response(self):
        unformatted_excel_file = super(FormattedSupervisoryReport, self).excel_response

        workbook = openpyxl.load_workbook(unformatted_excel_file)
        worksheet = workbook.get_active_sheet()

        red = PatternFill(
            start_color='FFEE1111',
            end_color='FFEE1111',
            fill_type='solid',
        )

        max_row = worksheet.max_row
        max_column = get_column_letter(worksheet.max_column)

        def percentile_fill(start_column, start_row, end_column, end_row,
                            percentile, fill):
            format_range = {
                'start_column': start_column,
                'start_row': start_row,
                'end_column': end_column,
                'end_row': end_row,
            }