Giter Site home page Giter Site logo

excel-formulas-calculator's Introduction

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, 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

excel-formulas-calculator's People

Contributors

ulalka avatar victormorozov1 avatar yoptar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.