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


Python Cell.fill方法代码示例

本文整理汇总了Python中openpyxl.cell.Cell.fill方法的典型用法代码示例。如果您正苦于以下问题:Python Cell.fill方法的具体用法?Python Cell.fill怎么用?Python Cell.fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openpyxl.cell.Cell的用法示例。


在下文中一共展示了Cell.fill方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_xls

# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import fill [as 别名]
def process_xls(data, config=None):
    header = data['header']
    title = header['title']
    origin = data['dataOrigin']
    book = Workbook()
    sheet = book.active
    doc_id = unique_id()
    files_path = config.get('files', 'path')

    if 'logoURL' in header:
        try:
            response = requests.get(header['logoURL'], stream=True)
            logo = Image(response.raw)
            logo = Image(logo.image.resize((100, 100)))
        except requests.ConnectionError as cerror:
            print(cerror, file=sys.stderr)

    else:
        logo = None


    hdr_bkg_color = header['backgroundColor']
    header_bkg = PatternFill(fill_type="solid",
                             start_color=hdr_bkg_color,
                             end_color=hdr_bkg_color)
    colformats = []
    coltypes = []
    has_formats = False

    columns = data.get('columns', [])

    try:
        for col in columns:
            colfmt = col.get('format', None)
            coltype = col.get('type', None)
            colformats.append(colfmt)
            coltypes.append(coltype)
        has_formats = True

    except TypeError:
        pass

    if origin == 'array':
        rows = data['rows']

        cell = Cell(sheet, value=title)
        cell.alignment = Alignment(horizontal='center',
                                   vertical='center')

        sheet.append(['', '', '', cell])

        sheet.merge_cells('A1:C1')
        sheet.merge_cells('D1:G1')

        for row in rows:
            cells = []
            for value in row:
                cell = Cell(sheet, value=value)
                cells.append(cell)
            sheet.append(cells)

    else:
        db = data['database']
        sql_query = data['sqlQuery']
        url_callback = data['urlCallback']
        title = data['title']
        columns = data['columns']

        """
        conn = pg_connect(host=db['host'],
                          database=db['name'],
                          password=db['password'],
                          user=db['user'])

        cursor = conn.cursor()
        cursor.execute(sql_query)
        """

        index = 0

        is_first = True

        for row in cursor:
            if is_first:
                sheet.merge_cells('A1:C1')
                sheet.merge_cells('D1:G1')

                sheet.append(['', '', '', cell])

                if logo:
                    sheet.add_image(logo, 'A1')

                headcells = []
                for col in columns:
                    cell = Cell(sheet, value=col['label'])
                    cell.fill = header_bkg
                    coltype = col.get('type', None)
                    colfmt = col.get('format', None)
                    columns_format.append(colfmt)
                    columns_type.append(coltype)
#.........这里部分代码省略.........
开发者ID:gamikun,项目名称:daogao,代码行数:103,代码来源:server.py


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