Skip to main content

xlreport – Easy Excel Export for Python objects

Project description

Xlreport – Easy Excel Export for Python Objects

Downloads PyPI version

Xlreport is a Python wrapper around xlsxwriter that makes it super easy to dump your data into Excel files. It takes care of all the formatting, so you don't have to mess with xlsxwriter's details. Most of the time, you'll just use the to_file function to throw whatever data you've got into a nicely formatted spreadsheet.

While Xlreport is mainly designed for 2D data (think tables with rows and columns), it can handle 1D data too. If you pass in a single-dimension list or array, it'll just fill up one column in your Excel file - simple as that.

Installation

pip install xlreport

Quick Start

# Generate some random data
from numpy.random import default_rng
arr = default_rng(42).random((100, 4))

# Save data to an Excel file and immediately open it
import xlreport as xl
header = ['col1', 'col2', 'col3', 'col4'] 
xl.to_file("test.xlsx", arr, header, title="Test numpy")

Supported Data Types

Xlreport works with various Python data structures:

  • Lists and tuples - Regular Python sequences
  • NumPy arrays - Numerical arrays with automatic conversion
  • Pandas DataFrames - With automatic index and column handling
  • Sets - Converted to list format
  • 1D data - Single columns for simple lists

📊 Multi-Sheet Excel Files

Create complex reports with multiple sheets and navigation links:

import xlreport as xl

# Create a multi-sheet file
exfile = xl.Exfile("report.xlsx")

# Add different datasets to different sheets
exfile.write(sales_data, title="Sales Report", worksheet_name="Sales")
exfile.write(customer_data, title="Customer Data", worksheet_name="Customers")
exfile.write(system_info, title="System Info", worksheet_name="Info", wrap=True)

# Add navigation links between sheets
exfile.add_links()

# Save and open the file
exfile.save(start=True)

Sample multisheets spreadsheet

📏 Intelligent Column Sizing

Xlreport addresses common challenges with Excel's automatic column sizing. Unlike xlsxwriter's worksheet.autofit() method which can produce undesirable results (like excessively wide columns for long strings), Xlreport offers a smart solution.

The column width is automatically calculated based on header text length using a logarithmic formula that provides optimal readability. You can fine-tune column widths by simply adding spaces to your headers:

# Control column width with spaces
headers = [
    "ID",                                    # Narrow column
    "Name          ",                        # Medium column  
    "Description - longer column          "  # Wide column
]
xl.to_file("sized.xlsx", data, headers, title="Custom Sizing")

🎨 Professional Formatting

  • Frozen headers - Top row stays visible when scrolling
  • Automatic number formatting - Decimals, integers, and currency
  • Text wrapping - Long text content with wrap=True option
  • Color-coded headers - Professional appearance with consistent styling
  • Unicode support - Handles international characters correctly

🔗 Sheet Navigation

When creating multi-sheet files, add_links() automatically creates clickable navigation links at the top of each sheet, making it easy to jump between different data views.

Advanced Usage

Working with Pandas DataFrames

import pandas as pd
import xlreport as xl

df = pd.DataFrame({
    "Product": ["Widget A", "Widget B", "Widget C"],
    "Sales": [1000, 1500, 800],
    "Profit": [200.50, 350.75, 120.25]
})

xl.to_file("dataframe.xlsx", df, title="Product Sales")

Text Wrapping for Long Content

# For data with long text content
long_text_data = [
    ["Topic", "Description"],
    ["AI", "Artificial Intelligence is a branch of computer science..."],
    ["ML", "Machine Learning is a subset of AI that focuses on..."]
]

xl.to_file("docs.xlsx", long_text_data, wrap=True, title="Documentation")

Custom Formatting Example

import xlreport as xl

# Create file with custom sheet name and formatting
exfile = xl.Exfile("custom_report.xlsx")

# Add data with specific formatting
exfile.write(
    data=financial_data,
    title="Q4 Financial Report",
    worksheet_name="Q4_Financials",
    wrap=False
)

# Add links and save
exfile.add_links()
exfile.save(start=True)  # Automatically opens the file

Dependencies

Use Cases

Xlreport is perfect for:

  • Data inspection - Quick visual analysis of datasets
  • Report generation - Professional-looking Excel reports
  • Data sharing - Easy export for stakeholders
  • Prototyping - Rapid data visualization during development
  • Multi-sheet reports - Complex documents with navigation

Alternative: HTML Tables

If you don't like spreadsheets there is better solution, check out df2tables - a companion library that generates interactive HTML tables from your data.

License

This code is licensed under MIT

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.


Need more control over Excel formatting? Check out the full xlsxwriter documentation for advanced features.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xlreport-0.0.7.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xlreport-0.0.7-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file xlreport-0.0.7.tar.gz.

File metadata

  • Download URL: xlreport-0.0.7.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for xlreport-0.0.7.tar.gz
Algorithm Hash digest
SHA256 b6a9be16c589b3bf8013d49caa42d532b6dfea966b0e1e0fcd52d7b056fe1909
MD5 5d92d1c7088dd02a43e6806dee7716ec
BLAKE2b-256 410b02bc20eaaf200318e98a6c2ba3daf4fe0b2076cad3b2570ddb63c36701b3

See more details on using hashes here.

File details

Details for the file xlreport-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: xlreport-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for xlreport-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 05230442351255d658cd4980dab4b856403cc5f1150320df8ee1703a35938aba
MD5 bdb3ac3aa190874ee933a496acb041d0
BLAKE2b-256 832349ce3bb0060ee72c2a1d06565cfee12d2faf3460099ecee56ffafcd08869

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page