Skip to main content

A Python package that provides convenience functions using XLWings to parametrize,

Project description

xl-engine

Use your existing Excel workbooks like they were Python programs: A utility built on XLWings to automate the input, execution, and data retrieval of your existing Excel Workbooks.

Installation

pip install xl-engine

Basic Usage

execute_workbook

Use execute_workbook when you want to execute a workbook once with known, provided parameters.

import xl_engine as xl

results = xl.execute_workbook(
    TEST_DATA_DIR / "example_wb.xlsx",
    cells_to_change = {"B1": 33, "B2": 66},
    cells_to_retrieve=['B4', 'B5'], # This can either be a list or a dict; see next example
    sheet_idx=1,
    new_filepath=TEST_DATA_DIR / "stored_results.xlsx"
)

# results
# {'B4': 22.0, 'B5': 11.0}

You can also use a dictionary in cells_to_retrieve to meaningfully label the results:

results2 = xl.execute_workbook(
    TEST_DATA_DIR / "example_wb.xlsx",
    cells_to_change = {"B1": 33, "B2": 66},
    cells_to_retrieve={'B4': "label1", 'B5': "label2"}, # Now a dict
    sheet_idx=1,
    new_filepath=TEST_DATA_DIR / "stored_results.xlsx"
)

# results2
# {'label1': 44.0, 'label2': 39.599999999999994}

excel_runner

Use excel_runner when you want to execute a workbook multiple times (static inputs) with multiple options (dynamic inputs).

import xl_engine as xl

# Creates a callable with the following function signature: callable(x: float | int) -> bool:
# When a value is a passed to dcr2, i.e. dcr2(some_value), it will return True if
# the value is greater-than-or-equal-to 2
dcr2 = xl.create_condition_check(2, "ge")

# static_inputs will be used to populate each workbook.
# Within each set of static inputs, a second sub-iteration will occur
# where the dynamic inputs will be input allowing you to test the
# results for different "options" of dynamic inputs.
# If the save conditions pass (return True for all keys), then a copy of the
# workbook will be saved to disk with the successful inputs recorded.
# A dictionary of all calculated results will be returned.
results = xl.excel_runner(
        TEST_DATA_DIR / "example_wb.xlsx",
        static_inputs={"B1": [10, 20], "Labels": ["C01", "C02"]},
        dynamic_inputs={
            "OptA": {"B2": 22},
            "OptB": {"B2": 33},
            "OptC": {"B2": 55},
        },
        success_conditions={"B6": dcr2},
        static_identifier_keys=["Labels"],
        result_labels={"B6": "meaningful_value"},
        save_dir=TEST_DATA_DIR / "design"
)

Return value (for the "example_wb.xlsx" file included in the tests directory):

{
    'C01': {
        'successful_key': None, # None of the options were successful for this case
        'OptA': {'meaningful_value': 1.2121212121212122}, 
        'OptB': {'meaningful_value': 0.8080808080808081}, 
        'OptC': {'meaningful_value': 0.48484848484848486}
    }, 
    'C02': {
        'successful_key': 'OptA', 
        'meaningful_value': 2.4242424242424243
    }
}

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

xl_engine-0.4.0.tar.gz (60.1 kB view details)

Uploaded Source

Built Distribution

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

xl_engine-0.4.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file xl_engine-0.4.0.tar.gz.

File metadata

  • Download URL: xl_engine-0.4.0.tar.gz
  • Upload date:
  • Size: 60.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for xl_engine-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b9dabc2eec7c4c8c2be55ca562a30a8f5f75db81af2930ff3ff3c28f5614597a
MD5 104004a2bc93cd188de2676b6c13c424
BLAKE2b-256 5e1bb3e33aad2e249b8acbdd6c5f49162ad88798fbf1b2510ed88f29d328e5c8

See more details on using hashes here.

File details

Details for the file xl_engine-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: xl_engine-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for xl_engine-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf2b6eb1ec31ac46b8b54831dae7a7b067a955c93342fc2a791dd284a2ebb5f9
MD5 f7d113a779e9eb3b5a46c3c882c49024
BLAKE2b-256 a8055385ef8ea7437857e0ff78d534aae4628a114f9b06a7963184732713e7a3

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