Python Forum
Python “Formula” Package: How do I parse Excel formula with a range of cells?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python “Formula” Package: How do I parse Excel formula with a range of cells?
#1
Hi,

I have read the documentation of the "Formula" package at https://formulas.readthedocs.io/en/stabl...ng-formula but it doesn't explain how to input the values for an Excel function that uses a range of cells.

Hope someone can help with the below queries. Thank you!

1) For Excel function with a range of values separated by :, how do I input into the parsed function?

EG

val='=SUM(A1:B3)'
func = formulas.Parser().ast(val)[1].compile()

print (func.inputs)
output:
OrderedDict([('A1:B3', <Ranges>(A1:B3))])

print (func(25,4))
output:
raise TypeError('too many positional arguments') from None

TypeError: too many positional arguments
2) Excel Function SUMPRODUCT doesn't seem to be supported, I get [[#VALUE!]] error

EG


val='=SUMPRODUCT(A1,B3)'
func = formulas.Parser().ast(val)[1].compile()

print (func.inputs)
output:
OrderedDict([('A1', <Ranges>(A1)), ('B3', <Ranges>(B3))])

print (func(25,4))
output:
[[#VALUE!]]
Reply
#2
1. I would use Pandas. Check the documentation for the read_excel function HERE. You can specify the file, sheet, and columns to be imported.

2. Once in Python, do not expect to use Excel functions. Different program. You will likely find equivalents. Again, check out Pandas.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to run utilities from a Python package? LugosisGhost 1 520 Dec-27-2023, 12:00 PM
Last Post: Larz60+
  Help using a dynamic array excel formula with XLWings FXMonkey 2 1,386 Jun-06-2023, 09:46 PM
Last Post: FXMonkey
Information Showing trendline formula in a table per product Carlossxx 0 734 May-03-2023, 08:34 AM
Last Post: Carlossxx
  math formula does not give the same result as bash script [SOLVED] AlphaInc 3 1,056 Apr-02-2023, 07:21 PM
Last Post: AlphaInc
  [split] Parse Nested JSON String in Python mmm07 4 1,656 Mar-28-2023, 06:07 PM
Last Post: snippsat
  Python package not seen in VSCode fmccabe80 6 3,405 Mar-06-2023, 10:01 PM
Last Post: fmccabe80
  [split] formula for validating monetary values? kakos_k9 1 830 Dec-17-2022, 09:28 PM
Last Post: woooee
  Openpyxl manipulate excel write formula SamLiu 0 1,135 Nov-04-2022, 03:00 PM
Last Post: SamLiu
  python read iperf log and parse throughput jacklee26 4 2,951 Aug-27-2022, 07:04 AM
Last Post: Yoriz
  Converting cells in excel to JSON format desmondtay 4 1,841 May-23-2022, 10:31 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020