Library to calculate excel formulas
Project description
Excel-formulas-calculator
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
- 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.
- 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, 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for excel-formulas-calculator-0.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 148bb9e7a00ff84facc5a41e6ade6de538fc465c097aa87934624597b7b55efa |
|
MD5 | 563808c4fcec80d8b569f91c64777d4f |
|
BLAKE2b-256 | be7660ae6fcac1232aff6e9b8a60ebccbac4b38a48e90a34ed0b5ac235f17e39 |
Close
Hashes for excel_formulas_calculator-0.4.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb3cadfe2df7188a88baa927af6d23c95a986a467c1c9616d6265e5041d78659 |
|
MD5 | 25847ae697bb7c012c2dbee4fbba9e24 |
|
BLAKE2b-256 | e2ba67da106feab681bb0a2dc6424ba211e90753a3330dade3a8abc062d3c411 |