Skip to main content

unifyxl

English | 日本語

A wrapper library that handles xlsx (openpyxl) and xls (xlrd + xlwt) through the same API. Unlike pandas, it reads and writes more than just values:

  • Formatting: fonts, background colors (fills), borders, alignment, number formats
  • Merged cells
  • Column widths, row heights, freeze panes

Installation

uv add unifyxl        # or: pip install unifyxl

Requires Python 3.14 or later. Dependencies: openpyxl, xlrd, xlwt. To install the latest development version, use uv add git+https://github.com/skrtk98/unifyxl.

Usage

import unifyxl
from unifyxl import Alignment, Border, Fill, Font, Side

# Load (the format is detected from the content, not the extension)
wb = unifyxl.load_workbook("input.xls")      # same for .xlsx / .xlsm
ws = wb.active                                # or wb["Sheet1"], wb[0]

cell = ws["B2"]                               # or ws.cell(2, 2), ws[2, 2]
cell.value                                    # value
cell.bg_color                                 # background Color (solid fills only; None otherwise)
cell.bg_color.rgb                             # "RRGGBB"
cell.font.bold, cell.font.color               # font
cell.border.bottom.style                      # "thin", etc.
cell.alignment.horizontal                     # "center", etc.
cell.number_format                            # "#,##0", etc.
cell.merged_range                             # merged range as CellRange, or None
ws.merged_ranges                              # all merged ranges in the sheet

# Write
ws["A1"] = "Header"
ws["A1"].font = Font(bold=True, size=14, color="FFFFFF")
ws["A1"].bg_color = "4472C4"
ws["A1"].border = Border.all("thin", "000000")
ws["A1"].alignment = Alignment(horizontal="center", vertical="center")
ws.merge_cells("A1:D1")
ws.set_column_width("A", 20)
ws.set_row_height(1, 30)
ws.freeze_panes = "A2"

# Change only part of a style (style objects are immutable; replace() makes a new one)
ws["B2"].font = ws["B2"].font.replace(italic=True)

# Copy another cell's whole style (works across formats too)
ws["C3"].style = ws["A1"].style

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

Create a new workbook with unifyxl.new_workbook("xlsx") or unifyxl.new_workbook("xls").

API overview

Object Main API
Workbook sheetnames, worksheets, active, create_sheet(), remove_sheet(), del wb[name], save(), convert(), format, theme_colors, theme_color()
Worksheet title, cell(), ws["A1"], ws["A1:C3"], iter_rows(), values(), append(), max_row, max_column, merge_cells(), unmerge_cells(), merged_ranges, get/set_column_width(), get/set_row_height(), freeze_panes
Cell value, style, font, fill, border, alignment, number_format, bg_color, merged_range, is_merged, is_formula, coordinate
Styles CellStyle(font, fill, border, alignment, number_format), Font, Fill (Fill.solid(color)), Border (Border.all(style, color)), Side, Alignment, Color (Color.theme_color(index, tint))
  • Row and column numbers are 1-based. Columns can be given as "A" or 1.
  • Colors are returned as Color objects; color.rgb is the "RRGGBB" value. None means "automatic".
  • When setting a color, besides Color you can pass "RRGGBB", "#rrggbb", "AARRGGBB" or (r, g, b); it is converted to a Color.
  • == between two Color objects is true only when rgb, theme and tint all match. A Color never equals a string (Color("FF0000") == "FF0000" is false). To compare the visible color, write color.rgb == "FF0000".
  • xlsx indexed colors are returned as RGB Colors. If an RGB or indexed color has a tint, it is returned as the RGB with the tint applied (if you change a style containing that color, it is saved as that tinted RGB; the visible color does not change).
  • xlsx theme colors are returned as Colors with color.theme (the theme color index) and color.tint (-1.0 to 1.0). color.rgb is the RGB with the tint applied. A theme color and an RGB color are not == even if they look the same. color.without_theme() gives the color without its theme reference, and style.without_theme() does the same for a whole style.
  • To specify a theme color, use wb.theme_color(4, tint=0.4). Indexes follow THEME_COLOR_NAMES (0: lt1, 1: dk1, 2: lt2, 3: dk2, 4-9: accent1-6, 10: hlink, 11: folHlink). The RGB value is resolved from that workbook's theme. wb.theme_colors returns the theme's 12 colors as a tuple of "RRGGBB" strings. Color.theme_color() resolves the RGB with the Office 2007-2010 default theme (the theme openpyxl writes to new workbooks).
  • Theme colors are saved to xlsx as theme references, so they follow a theme change in Excel. The reference is also kept when you change part of a style (e.g. cell.font = cell.font.replace(bold=True)).
  • Rows range from 1 to 1048576 and columns from 1 to 16384 (A to XFD). Out-of-range values raise ValueError.
  • Writing a value to a merged cell other than the top-left one raises MergedCellError.
  • Merging clears the values and styles of all cells except the top-left one, and the top-left cell's borders are carried over to the cells on the edge of the range. If the top-left cell has no right or bottom border, it takes the bottom-right cell's (both formats follow openpyxl's behavior).
  • Units: column width is in Excel character units, row height in points. Row heights must be greater than 0 and at most 409 (0 is not allowed because openpyxl does not save it; hiding rows is not supported yet).
  • If you need the underlying objects, use wb.openpyxl_workbook and ws.openpyxl_worksheet (xlsx only).

Format differences and limitations

xlsx (openpyxl)

  • Column settings without a width (columns that are only grouped or hidden, etc.) are read by openpyxl as width 13. So even if you clear a width with set_column_width(col, None), such columns read back as 13.
  • Because the openpyxl objects are wrapped directly, parts you don't touch (comments, data validation, etc.) are saved as far as openpyxl preserves them.
  • Plain openpyxl drops the styles of merged cells other than the top-left one on load (it only moves the bottom-right cell's right and bottom borders to the top-left cell). As a result, borders of the top-right and bottom-left cells, fills, number formats and so on are lost. unifyxl re-reads the sheet XML after loading and restores each merged cell's style from the file.
  • When you change part of a style (cell.font = ... etc.), only the assigned part (font, fill, border, alignment or number format) is changed and the other parts are kept. For example, cell.font = ... keeps fills the unifyxl model cannot express, such as gradient fills. Settings the model cannot express inside the assigned part are lost, though (text direction for cell.alignment = ..., diagonal borders for cell.border = ...).
  • Gradient fills cannot be read (they are returned as no fill).
  • The theme itself (its color definitions) is read-only and cannot be changed.
  • Theme colors in the srgbClr, sysClr, scrgbClr and hslClr notations are read. Colors in other notations such as prstClr, and colors with color transform child elements such as lumMod, are treated as the default theme color, with a warning.
  • If you load and save an xlsx whose theme references images (texture fills, etc.), the images are not saved and only the references remain in the theme XML, because openpyxl writes back only the theme XML it loaded. When converting formats, a theme XML that references other parts (has attributes such as r:embed) is not carried over; only its color definitions are.

xls (xlrd + xlwt)

  • xlrd only reads and xlwt only writes. So xls files are converted into an in-memory model on load and rebuilt with xlwt on save. Charts, images, comments, data validation, conditional formatting and the like are not saved.
  • xlrd cannot read formulas. When you read an xls file, formula cells contain their last calculated value. Writing a string such as "=A1*2" saves it as an xlwt formula (formulas xlwt cannot parse raise ValueError on save). xlwt does not write calculated results, so reading the file back with unifyxl gives an empty string.
  • Colors are assigned to the palette (56 colors). The palette of a loaded file is kept, as are colors referenced by number formats such as [Color10]. If there are not enough free slots, the colors used by the fewest cells are replaced by the nearest color, with a warning.
  • The limits are 65536 rows × 256 columns and 4000 distinct cell formats. Exceeding them raises FormatLimitError, also when converting from xlsx to xls.
  • Indentation is limited to 15 (larger values are clipped to 15).
  • Integral numbers are returned as int (to match xlsx results).
  • xls has no themes, so only the RGB value of a theme color is saved. For a workbook loaded from an xls file, theme_colors returns the Office 2007-2010 default theme. The in-memory model keeps theme references, so theme colors set in an xls workbook are written as theme references when it is saved as xlsx.
  • Converting formats (convert()) also carries over the theme's color definitions. Even if you convert an xlsx with a custom theme to xls and back to xlsx in memory, the colors theme references point to do not change. An xls file cannot store a theme, though, so if you save it as xls and read it back, the theme references are gone and only the RGB values remain.

Both formats

  • Values can be str, int, float, bool, datetime, date, time, timedelta, Decimal (converted to float) or None. NaN and infinity raise ValueError; strings longer than 32767 characters raise FormatLimitError.
  • Assigning a date or time sets a number format such as yyyy-mm-dd h:mm:ss automatically if the current number format is not a date format (same as openpyxl). On load, dates are returned as datetime, values below 1 as time, and elapsed-time formats such as [h]:mm:ss as timedelta. Time precision is milliseconds in both formats (like openpyxl, microseconds are rounded to milliseconds when the file is saved and read back).
  • Assigning a string starting with "=" creates a formula, and assigning an error value string such as "#DIV/0!" creates an error value (same as openpyxl). A plain string starting with "=" read from a file stays a string when saved or converted.
  • Inserting or deleting rows and columns, diagonal borders, cell protection and hyperlinks are not supported.

License

MIT License. See LICENSE.

Development

uv sync
uv run pytest

Metadata

Release files for unifyxl 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for unifyxl 0.1.0
File Size Uploaded Provenance Actions
unifyxl-0.1.0.tar.gz 44.1 kB With provenance Details for unifyxl-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for unifyxl 0.1.0
File Interpreter ABI Platform Actions
unifyxl-0.1.0-py3-none-any.whl Python 3 none any Details for unifyxl-0.1.0-py3-none-any.whl

Total release size: 92.8 kB

Release files / unifyxl-0.1.0.tar.gz

Download URL unifyxl-0.1.0.tar.gz
Size 44.1 kB
Tags Source
SHA-256 checksum
How to use checksums
67e0a8be3dc81d9c6bfd87afc9ad11a842649061a5b31c86cdfd796949afbd6b
BLAKE2b-256 checksum
How to use checksums
e3797588923020a095c49d8b75c714c8500b66d1f1034d9a650ef975a58975ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / unifyxl-0.1.0-py3-none-any.whl

Download URL unifyxl-0.1.0-py3-none-any.whl
Size 48.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
423634954539728496e8e44871d75ea392d60507f29ce9c274297302c3b47bc1
BLAKE2b-256 checksum
How to use checksums
8f0031594b42ecac147809dd5507b498824c72b9bb097fd04323e85ab84fc44c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Security for unifyxl 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for unifyxl-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page