Skip to main content

ExcelHelper

ExcelHelper is a Python library that simplifies Excel manipulation using the openpyxl library. It provides an easy-to-use interface for common Excel operations, including working with formulas.

Installation

You can install ExcelHelper using pip:

pip install excel-helper

Usage

Here's a quick example of how to use ExcelHelper:

from excel_helper import ExcelHelper

# Create a new Excel file
excel = ExcelHelper("example.xlsx")
excel.create_new_workbook()

# Write some data
excel.write_range(1, 1, [
    ["Product", "Quantity", "Price"],
    ["Apple", 10, 0.5],
    ["Banana", 15, 0.3],
    ["Orange", 8, 0.7]
])

# Calculate total for each product
excel.set_formula(2, 4, "=B2*C2")
excel.set_formula(3, 4, "=B3*C3")
excel.set_formula(4, 4, "=B4*C4")

# Calculate sum of quantities and total price
excel.sum_range(2, 2, 4, 2, 5, 2)  # Sum of quantities
excel.sum_range(2, 4, 4, 4, 5, 4)  # Sum of totals

# Calculate average price
excel.average_range(2, 3, 4, 3, 5, 3)

# Use IF formula
excel.if_formula(5, 4, "High Sales", "Low Sales", 5, 5)

# Use VLOOKUP
excel.write_cell(7, 1, "Banana")
excel.vlookup(7, 1, 1, 1, 4, 3, 3, 7, 2)

excel.auto_fit_columns()
excel.save_workbook()

Features

  • Open, create, and save workbooks
  • Select sheets
  • Read and write individual cells
  • Read and write rows and columns
  • Read and write ranges of cells
  • Apply styles to cells
  • Auto-fit column widths
  • Work with formulas (SUM, AVERAGE, COUNT, IF, VLOOKUP)

API Reference

ExcelHelper(filename)

Create a new ExcelHelper instance.

  • filename: The name of the Excel file to work with.

Methods

  • open_workbook(): Open the Excel workbook.
  • save_workbook(): Save the Excel workbook.
  • create_new_workbook(): Create a new Excel workbook.
  • select_sheet(sheet_name): Select a sheet by name.
  • write_cell(row, col, value): Write a value to a specific cell.
  • read_cell(row, col): Read the value from a specific cell.
  • write_row(row, data): Write a list of values to a row.
  • read_row(row): Read all values from a row.
  • write_column(col, data): Write a list of values to a column.
  • read_column(col): Read all values from a column.
  • write_range(start_row, start_col, data): Write a 2D list of values to a range of cells.
  • read_range(start_row, start_col, end_row, end_col): Read a range of cells and return a 2D list of values.
  • apply_style(row, col, style): Apply a style to a specific cell.
  • auto_fit_columns(): Auto-fit all columns in the active sheet.
  • set_formula(row, col, formula): Set a formula in a specific cell.
  • get_formula(row, col): Get the formula from a specific cell.
  • copy_formula(from_row, from_col, to_row, to_col): Copy a formula from one cell to another, adjusting cell references.
  • sum_range(start_row, start_col, end_row, end_col, result_row, result_col): Sum a range of cells and put the result in another cell.
  • average_range(start_row, start_col, end_row, end_col, result_row, result_col): Calculate the average of a range of cells.
  • count_range(start_row, start_col, end_row, end_col, result_row, result_col): Count non-empty cells in a range.
  • if_formula(condition_row, condition_col, true_value, false_value, result_row, result_col): Set an IF formula in a specific cell.
  • vlookup(lookup_value_row, lookup_value_col, table_start_row, table_start_col, table_end_row, table_end_col, col_index, result_row, result_col): Set a VLOOKUP formula in a specific cell.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any problems or have any questions, please open an issue on the GitHub repository.

Release files for excel-helper 1.0.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 excel-helper 1.0.0
File Size Uploaded
excel-helper-1.0.0.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for excel-helper 1.0.0
File Interpreter ABI Platform
excel_helper-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.5 kB

Release files / excel-helper-1.0.0.tar.gz

Download URL excel-helper-1.0.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d05c28a97d911258229b14b2bf3623657e12adc31120183492347311ec1e2269
BLAKE2b-256 checksum
How to use checksums
8ee78aed36af9ca0ee281200aca4e7dc58a4c6d31236d80370b52f7d23141c06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.3

Release files / excel_helper-1.0.0-py3-none-any.whl

Download URL excel_helper-1.0.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb605e1d7e59c4c083d1ee5a93f0b414c115b2e836fcca9e05d0b8412438f865
BLAKE2b-256 checksum
How to use checksums
fda85f789b0f345c9fe609dfa5f5a2092139ae08f1dd5add8cad967e87e19d22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.0

2 release files

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