How to use the openpyxl.styles.Border 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 InvestmentSystems / table-compositor / table_compositor / xlsx_styles.py View on Github external
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,
                top=thin_black, bottom=thin_white)

        bottom_right_border = Border(left=thin_white, right=thin_black,
                top=thin_white, bottom=thin_black)
        bottom_left_border = Border(left=thin_black, right=thin_white,
                top=thin_white, bottom=thin_black)
        bottom_border = Border(left=thin_white, right=thin_white,
                top=thin_white, bottom=thin_black)

        thin_border = Border(left=thin_white, right=thin_white,
                        top=thin_white, bottom=thin_white)

        thin_black_border = Border(
            left=thin_black, right=thin_black,
            top=thin_black, bottom=thin_black)
        thin_white_border = Border(
            left=thin_white, right=thin_white,
            top=thin_white, bottom=thin_white)
        thick_side_border = Border(
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',
github airbus-seclab / bta / bta / formatters / excel.py View on Github external
from bta.formatters import Formatter
import StringIO
from collections import defaultdict

from openpyxl.workbook import Workbook
from openpyxl.styles import Style, Color, Font, Border, Side, PatternFill, fills, borders
headcolor = Color(rgb="ff9dc5ff")
oddcolor = Color(rgb="ffffefd4")
evencolor = Color(rgb="ffffd794")
hline = Border(bottom=Side(border_style=borders.BORDER_THICK))
headstyle = Style(font=Font(name='Courier', size=11, bold=True),
                  fill=PatternFill(fill_type=fills.FILL_SOLID,
                                   start_color=headcolor,
                                   end_color=headcolor),
                  border=Border(top=Side(border_style=borders.BORDER_THICK),
                                bottom=Side(border_style=borders.BORDER_THICK)),
                  )
oddstyle =  Style(font=Font(name='Courier', size=11),
                  fill=PatternFill(fill_type=fills.FILL_SOLID,
                                   start_color=oddcolor,
                                   end_color=oddcolor),
              )
evenstyle = Style(font=Font(name='Courier', size=11),
                  fill=PatternFill(fill_type=fills.FILL_SOLID,
                                   start_color=evencolor,
                                   end_color=evencolor),
             )
linestyle = [oddstyle, evenstyle]

@Formatter.register
class Excel(Formatter):
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 CarlKing5019 / python3-cookbook-personal / basic / samples / excel / generate_schema.py View on Github external
common_style = basic_style.copy()
    link_style = basic_style.copy(font=Font(
        name='Microsoft YaHei', color=colors.BLUE, underline='single'))
    table_data = load_schema(schema_name)
    wb = Workbook()
    wb.active.title = "首页列表"

    for table in table_data:
        ws = wb.create_sheet(title=table[0])
        ws.merge_cells('E3:I3')  # 合并单元格
        ws['E3'].style = title_style
        ws['F2'].style = Style(border=Border(
            bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')))
        ws['G2'].style = Style(border=Border(
            bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')))
        ws['H2'].style = Style(border=Border(
            bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')))
        ws['I2'].style = Style(border=Border(
            bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')))
        ws['J3'].style = Style(border=Border(
            left=Side(border_style=borders.BORDER_THIN, color='FF000000')))
        ws['E3'] = table[0]
        ws['E4'].style = header_style
        ws['E4'] = '列名'
        ws['F4'].style = header_style
        ws['F4'] = '类型'
        ws['G4'].style = header_style
        ws['G4'] = '空值约束'
        ws['H4'].style = header_style
        ws['H4'] = '默认值'
        ws['I4'].style = header_style
        ws['I4'] = '备注'
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',
github airbus-seclab / bta / bta / formatters / excel.py View on Github external
# This file is part of the BTA toolset
# (c) Airbus Group CERT, Airbus Group Innovations and Airbus DS CyberSecurity

import openpyxl

from bta.formatters import Formatter
import StringIO
from collections import defaultdict

from openpyxl.workbook import Workbook
from openpyxl.styles import Style, Color, Font, Border, Side, PatternFill, fills, borders
headcolor = Color(rgb="ff9dc5ff")
oddcolor = Color(rgb="ffffefd4")
evencolor = Color(rgb="ffffd794")
hline = Border(bottom=Side(border_style=borders.BORDER_THICK))
headstyle = Style(font=Font(name='Courier', size=11, bold=True),
                  fill=PatternFill(fill_type=fills.FILL_SOLID,
                                   start_color=headcolor,
                                   end_color=headcolor),
                  border=Border(top=Side(border_style=borders.BORDER_THICK),
                                bottom=Side(border_style=borders.BORDER_THICK)),
                  )
oddstyle =  Style(font=Font(name='Courier', size=11),
                  fill=PatternFill(fill_type=fills.FILL_SOLID,
                                   start_color=oddcolor,
                                   end_color=oddcolor),
              )
evenstyle = Style(font=Font(name='Courier', size=11),
                  fill=PatternFill(fill_type=fills.FILL_SOLID,
                                   start_color=evencolor,
                                   end_color=evencolor),
github CarlKing5019 / python3-cookbook-personal / basic / samples / excel / generate_schema.py View on Github external
ws['E{}'.format(idx + 5)].style = common_style
            ws['E{}'.format(idx + 5)] = each_column[0]
            ws['F{}'.format(idx + 5)].style = common_style
            ws['F{}'.format(idx + 5)] = each_column[1]
            ws['G{}'.format(idx + 5)].style = common_style
            ws['G{}'.format(idx + 5)] = each_column[2]
            ws['H{}'.format(idx + 5)].style = common_style
            ws['H{}'.format(idx + 5)] = each_column[3]
            ws['I{}'.format(idx + 5)].style = common_style
            ws['I{}'.format(idx + 5)] = each_column[4]
    ws = wb['首页列表']
    ws.merge_cells('D3:F3')
    ws['D3'].style = title_style
    ws['E2'].style = Style(border=Border(
        bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')))
    ws['F2'].style = Style(border=Border(
        bottom=Side(border_style=borders.BORDER_THIN, color='FF000000')))
    ws['G3'].style = Style(border=Border(
        left=Side(border_style=borders.BORDER_THIN, color='FF000000')))
    ws['D3'] = 'MySQL数据库系统表'
    ws['D4'].style = header_style
    ws['D4'] = '编号'
    ws['E4'].style = header_style
    ws['E4'] = '表名'
    ws['F4'].style = header_style
    ws['F4'] = '详情链接'
    ws.column_dimensions['D'].width = 15
    ws.column_dimensions['E'].width = 25
    ws.column_dimensions['F'].width = 35
    for inx, val in enumerate(table_data):
        ws['D{}'.format(inx + 5)].style = common_style
        ws['D{}'.format(inx + 5)] = inx + 1
github limodou / uliweb / uliweb / utils / xltools.py View on Github external
def border_add(border, top=None, right=None, left=None, bottom=None):
            top = top or border.top
            left = left or border.left
            right = right or border.right
            bottom = bottom or border.bottom
            return Border(top=top, left=left, right=right, bottom=bottom)