unifyxl

Read and write Excel files without losing the formatting of merged cells, in both xlsx and xls.

When openpyxl loads an xlsx file, every cell of a merged range except the top-left one loses its background color, and only the outer edge of its borders survives. unifyxl re-reads each merged cell’s style from the sheet XML and restores it.

The same API also handles legacy xls (via xlrd and xlwt), and converts between the two formats with formatting intact. Unlike pandas, it reads and writes more than values:

  • Formatting: fonts, background colors (fills), borders, alignment, number formats

  • Merged cells, including the formatting of every cell in the range

  • Column widths, row heights, freeze panes

  • Theme colors (kept as theme references in xlsx)

  • Shapes: read, edit, add and remove them, including position, fill, outline and text (xlsx)

Installation

Install it from PyPI (Python 3.11 or later):

uv add unifyxl
# or
pip install unifyxl

To try the latest development version, install from GitHub instead: uv add git+https://github.com/skrtk98/unifyxl.

Quick start

import unifyxl
from unifyxl import Border, BorderStyle, Font

# The format is detected from the file contents, not the extension.
wb = unifyxl.load_workbook("input.xls")
ws = wb.active

cell = ws["B2"]
print(cell.value, cell.bg_color, cell.font.bold, ws.merged_ranges)

ws["A1"] = "Header"
ws["A1"].font = Font(bold=True, color="FFFFFF")
ws["A1"].bg_color = "4472C4"
ws["A1"].border = Border.all(BorderStyle.THIN, "000000")
ws.merge_cells("A1:D1")

wb.save("output.xlsx")   # a different extension converts on save

Rows and columns are 1-based everywhere. Style objects such as Font are immutable; use replace() to derive a modified copy and assign it back to the cell.

More documentation