agate-excel

0.4.2 · active · verified Wed Apr 15

agate-excel is an extension for the `agate` data analysis library, providing read support for both older XLS and newer XLSX Excel file formats. The current version is 0.4.2, released on December 15, 2025, and it appears to be actively maintained, supporting recent Python versions including 3.13 and 3.14. It integrates seamlessly with `agate` by adding file reading methods directly to `agate.Table` instances.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to read data from an XLSX file using `agate-excel`. It first creates a simple XLSX file using `openpyxl` (if available) and then loads it into an `agate.Table` object. The methods `from_xls()` and `from_xlsx()` are added directly to `agate.Table` after `import agateexcel`.

import agate
import agateexcel
import os

# Create a dummy Excel file for demonstration
# In a real scenario, 'example.xlsx' would already exist.

# Using openpyxl to create a simple .xlsx file
try:
    from openpyxl import Workbook
    wb = Workbook()
    ws = wb.active
    ws['A1'] = 'Header1'
    ws['B1'] = 'Header2'
    ws['A2'] = 1
    ws['B2'] = 'Value1'
    ws['A3'] = 2
    ws['B3'] = 'Value2'
    xlsx_path = 'example.xlsx'
    wb.save(xlsx_path)

    print(f"Created temporary Excel file: {xlsx_path}")

    # Load an XLSX file
    table_xlsx = agate.Table.from_xlsx(xlsx_path)
    print("\nData from XLSX:")
    table_xlsx.print_table()

    # You can also specify a sheet by name or index
    # table_xlsx_sheet2 = agate.Table.from_xlsx(xlsx_path, sheet=0)

    # Clean up the dummy file
    os.remove(xlsx_path)
    print(f"Removed temporary Excel file: {xlsx_path}")

except ImportError:
    print("openpyxl not installed. Cannot create dummy .xlsx file.")
    print("Please install openpyxl (pip install openpyxl) to run the full quickstart example.")
except Exception as e:
    print(f"An error occurred: {e}")

# Note: Reading .xls files requires xlrd, which is not used in this dummy file creation.
# Example for XLS (assuming 'example.xls' exists):
# table_xls = agate.Table.from_xls('example.xls')

view raw JSON →