Пример #1
0
def _get_formatted_workbook():
    wb = Workbook()
    ws = wb.active
    ws.title = ugettext('Indicator plan')

    row_num = START_ROW
    col_num = START_COLUMN

    # Set widths of columns
    _set_column_widths(ws, 1, 3)  # spacer col
    for col in COLUMNS:
        width = col.get('cell_width')
        if width:
            _set_column_widths(ws, col_num, width)
        col_num += 1

    # Title
    col_num = START_COLUMN
    cell = ws.cell(row_num, col_num,
                   ugettext('Indicator plan').encode('utf-8'))
    apply_title_styling(cell)
    ws.merge_cells(start_row=row_num,
                   start_column=col_num,
                   end_row=row_num,
                   end_column=col_num + len(COLUMNS) - 1)
    row_num += 1

    # Category groupings
    col_num = START_COLUMN
    for category_name, columns in columns_by_category():
        num_columns = len(list(columns))
        cell = ws.cell(row_num, col_num, category_name.encode('utf-8'))
        ws.merge_cells(start_row=row_num,
                       start_column=col_num,
                       end_row=row_num,
                       end_column=col_num + num_columns - 1)
        apply_label_styling(cell)
        col_num += num_columns
    row_num += 1

    # Column names
    col_num = START_COLUMN
    for column_name in column_names():
        cell = ws.cell(row_num, col_num, column_name.encode('utf-8'))
        apply_label_styling(cell)
        col_num += 1
    row_num += 1
    return wb, row_num
Пример #2
0
def add_title_cell(ws, row, column, value):
    cell = ws.cell(row=row, column=column)
    cell.value = value
    cell.font = TITLE_FONT
    apply_title_styling(cell)
    return cell