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
  MPEG DASH Package implementation similar to M3U8 package anantha_narayanan 0 593 Feb-06-2025, 03:55 AM
Last Post: anantha_narayanan
  How to run utilities from a Python package? LugosisGhost 1 1,206 Dec-27-2023, 12:00 PM
Last Post: Larz60+
  Help using a dynamic array excel formula with XLWings FXMonkey 2 2,820 Jun-06-2023, 09:46 PM
Last Post: FXMonkey
Information Showing trendline formula in a table per product Carlossxx 0 1,689 May-03-2023, 08:34 AM
Last Post: Carlossxx
  math formula does not give the same result as bash script [SOLVED] AlphaInc 3 1,763 Apr-02-2023, 07:21 PM
Last Post: AlphaInc
  [split] Parse Nested JSON String in Python mmm07 4 2,774 Mar-28-2023, 06:07 PM
Last Post: snippsat
  Python package not seen in VSCode fmccabe80 6 6,845 Mar-06-2023, 10:01 PM
Last Post: fmccabe80
  [split] formula for validating monetary values? kakos_k9 1 1,333 Dec-17-2022, 09:28 PM
Last Post: woooee
  Openpyxl manipulate excel write formula SamLiu 0 2,280 Nov-04-2022, 03:00 PM
Last Post: SamLiu
  python read iperf log and parse throughput jacklee26 4 4,733 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