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


Messages In This Thread
Python “Formula” Package: How do I parse Excel formula with a range of cells? - by JaneTan - Jul-12-2021, 06:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 0 208 Mar-27-2024, 01:16 PM
Last Post: ann23fr
  How to run utilities from a Python package? LugosisGhost 1 450 Dec-27-2023, 12:00 PM
Last Post: Larz60+
  Help using a dynamic array excel formula with XLWings FXMonkey 2 1,303 Jun-06-2023, 09:46 PM
Last Post: FXMonkey
Information Showing trendline formula in a table per product Carlossxx 0 673 May-03-2023, 08:34 AM
Last Post: Carlossxx
  math formula does not give the same result as bash script [SOLVED] AlphaInc 3 984 Apr-02-2023, 07:21 PM
Last Post: AlphaInc
  [split] Parse Nested JSON String in Python mmm07 4 1,550 Mar-28-2023, 06:07 PM
Last Post: snippsat
  Python package not seen in VSCode fmccabe80 6 3,247 Mar-06-2023, 10:01 PM
Last Post: fmccabe80
  [split] formula for validating monetary values? kakos_k9 1 760 Dec-17-2022, 09:28 PM
Last Post: woooee
  Openpyxl manipulate excel write formula SamLiu 0 1,063 Nov-04-2022, 03:00 PM
Last Post: SamLiu
  python read iperf log and parse throughput jacklee26 4 2,803 Aug-27-2022, 07:04 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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