Wiki

Clone wiki

openpyxl / Home

Fork of openpyxl

The purpose of this fork of openpyxl is to add in formatting features. The objectives are two-fold:

  1. To fix some of the cell formatting features, such as merged cells, print settings, and font colors.
  2. For openpyxl to read and preserve existing formatting structures.

Examples of new features

Font Colors

Main branch of openpyxl already handles font colors, like:

from openpyxl.workbook import Workbook
from openpyxl.style import Color

wb = Workbook()
ws = wb.worksheets[0]
ws.cell('A1').value = 'This is red'
ws.cell('A1').style.font.color.index = Color.RED

Edit Print Settings

from openpyxl.workbook import Workbook

wb = Workbook()
ws = wb.worksheets[0]

ws.page_setup.orientation = ws.ORIENTATION_LANDSCAPE
ws.page_setup.paperSize = ws.PAPERSIZE_TABLOID
ws.page_setup.fitToPage = True
ws.page_setup.fitToHeight = 0
ws.page_setup.fitToWidth = 1
ws.page_setup.horizontalCentered = True
ws.page_setup.verticalCentered = True

Merge / Unmerge cells

from openpyxl.workbook import Workbook

wb = Workbook()
ws = wb.worksheets[0]

ws.merge_cells('A1:B1')
ws.unmerge_cells('A1:B1')

# or
ws.merge_cells(start_row=2,start_col=1,end_row=2,end_col=4)
ws.unmerge_cells(start_row=2,start_col=1,end_row=2,end_col=4)
from openpyxl.workbook import Workbook

wb = Workbook()
ws = wb.worksheets[0]

ws.header_footer.center_header.text = 'My Excel Page'
ws.header_footer.center_header.font_size = 14
ws.header_footer.center_header.font_name = "Tahoma,Bold"
ws.header_footer.center_header.font_color = "CC3366"

# Or just
ws.header_footer.right_footer.text = 'My Right Footer'

Updated