Skip to main content

Library to calculate excel formulas

Project description

Excel-formulas-calculator

ci-badge pypi-badge py-version-badge

Excel-formulas-calculator (EFC) is a high-level Py23 library that allows you to calculate Excel formulas on any OS.

Openpyxl interface

from openpyxl import load_workbook
from efc.interfaces.iopenpyxl import OpenpyxlInterface

wb = load_workbook('test.xlsx')
interface = OpenpyxlInterface(wb=wb, use_cache=True)

# e.g. A1 stores formula '=1 + 2', then result = 3
result = interface.calc_cell('A1', 'Worksheet1')

# EFC does not change the source document
print(wb['Worksheet1']['A1'].value)  # prints '=1 + 2'

# If you need to replace a formula in a workbook with a value, 
# you need to do this
wb['Worksheet1']['A1'].value = interface.calc_cell('A1', 'Worksheet1')
print(wb['Worksheet1']['A1'].value)  # prints '3'

# The EFC does not track changes to values in the workbook. 
# If the use_cache=True option is used, the calculated formulas 
# are not recalculated again when they are accessed.
# e.g. A2 = 2, A3 = 1, A4 = A2 + A3
print(interface.calc_cell('A4', 'Worksheet1'))  # prints '3'
wb['Worksheet1']['A2'].value = 1234
print(interface.calc_cell('A4', 'Worksheet1'))  # prints '3'

# If you have made changes to the workbook, then you need to reset 
# the cache to get up-to-date results
interface.clear_cache()
print(interface.calc_cell('A4', 'Worksheet1'))  # prints '1235'

# You can disable caching of results, 
# but then when you run a large number of related formulas, 
# the calculation speed will decrease significantly

Custom interface

  1. Inherit from efc.interface.BaseExcelInterface in your excel file class and implement abstract methods. This class will be used to get data from excel file using any library you want.
  2. Use calc_cell to calculate cell's formula.

Functionality

  • Arithmetic: -, +, *, /, ^, ()
  • Comparison: <>, >, >=, <, <=, =
  • String concatenation: &
  • Functions: ABS, AND, AVERAGE, AVERAGEIFS, COLUMN, CONCATENATE, COUNT, COUNTA, COUNTIF, COUNTIFS, COUNTBLANK, FLOOR, IF, IFS, IFERROR, INDEX, ISBLANK, ISERROR, HLOOKUP, LARGE, LEN, LEFT, LOWER, MATCH, MAX, MID, MIN, MOD, NOT, OFFSET, OR, RIGHT, ROUND, ROUNDDOWN, ROW, SEARCH, SMALL, SUBSTITUTE, SUM, SUMIF, SUMIFS, SUMPRODUCT, TRIM, VLOOKUP, YEARFRAC, UNIQUE, UPPER
  • All variations of the spelling of the cell and range addresses (linked docs will be skipped)
  • Formula cell offset - this can be useful when calculating shared formulas

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

excel_formulas_calculator-0.5.1.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

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

excel_formulas_calculator-0.5.1-py2.py3-none-any.whl (43.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file excel_formulas_calculator-0.5.1.tar.gz.

File metadata

File hashes

Hashes for excel_formulas_calculator-0.5.1.tar.gz
Algorithm Hash digest
SHA256 939d2ed7745edb37175ca710c23893b2cbfa8c6c7bab3c8b0f37c7e4f61467b9
MD5 6574f08f1b30530dd920ae51ee4a1671
BLAKE2b-256 0c52f2e841d18b86cca8ec552dc8ef9c11590090ed137bab4fa9c69d4919b5ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for excel_formulas_calculator-0.5.1.tar.gz:

Publisher: python-publish.yml on ulalka/excel-formulas-calculator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file excel_formulas_calculator-0.5.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for excel_formulas_calculator-0.5.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 06451f80ed534eef94ddf3f99827dbb7c4bf3bef9e55d05d18d929a7c3268e63
MD5 21c697b47f0646001085da25e27c9b15
BLAKE2b-256 265ccbcd859601d03811fb8ef92bce27970476bb95cf5bc915ac6accb1995099

See more details on using hashes here.

Provenance

The following attestation bundles were made for excel_formulas_calculator-0.5.1-py2.py3-none-any.whl:

Publisher: python-publish.yml on ulalka/excel-formulas-calculator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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