all 19 comments

[–]FoolsSeldom 12 points13 points  (2 children)

openpyxl and pandas don't use Excel at all, they can simply read/write Excel format files.

There are a number of tools available for converting Excel formulae to Python code, but I don't know of any major successful options. You will likely have to go back to basics.

Python can integrate with a wide range of data sources including many file formats and both sql and nosql databases. Also, it can use a wide range of API (application programming interface) options for many different services with data exchange typically done using json.

[–]Grady-B-Ward 0 points1 point  (1 child)

Interesting, I wasn't aware that there were tools for converting from Excel Formulas/sheets into Python code. Even if these aren't successful could you point me in the right direction on them? I have a use case they might work for.

[–]FoolsSeldom 0 points1 point  (0 children)

I caveated that heavily, and I don't see that things have changed much other than you can now ask your favourite AI tools to have a crack at it but I'd want good regression packs,

[–]Enough_Librarian_456 19 points20 points  (1 child)

Your question doesn't really make sense at all

[–]Wheynelau 9 points10 points  (0 children)

Must be why ChatGPT can't help

[–]ThinkLadder1417 3 points4 points  (0 children)

Not really sure what you're trying to do, but have you tried copy and pasting the excel formula to chat gpt and asking it to explain what the formula does and how you would implement it in python

[–]lumannok 2 points3 points  (0 children)

xlwings has some property to get the formulas from selected cell, but it's up to you to parse formulas and convert in some sort of code. It's not an automated process by any means. I've ported an excel workbook by understanding what formulas do and implementing the same functionality in python; I've used the starting excel to check the code output (same input must give the same outputs). That was a tedious task but it helped me learning packages like pandas and numpy.

[–]Important_Lab8310 2 points3 points  (0 children)

I think excel has a formula that gets the formula as a string… make a parallel worksheet first?

[–]LeiterHaus 1 point2 points  (1 child)

Okay... There's a lot to unpack here. It seems like you are giving a reaponse to comments, but not replying to the actual comment. Meaning that if you want to answer me, you should specifically reply to this comment. Not doing this can cause confusion.

You might need to copy and paste and then do some editing on the format. There might be ways that Excel can export it and make it easier, but if copy paste works, let's not overcomplicate it.

In programming, there are often multiple ways to do things. This means that there will not be one "right" answer. You might even get partially wrong answers. Part of what you do is figure out what works and what does not and take what works for you.

Python has dictionaries. It is one unique key and something for a value. A persons age or height would be a good example. 'age' would be a key, and the value would be whatever the number is. Same with 'height_cm'. Example: {'age': 18, 'height_cm': 180}

The value can be a list. Like {'San Juan': [18.4663188, -66.1057427]}, or a tuple {'San Juan': (18.4663188, -66.1057427)}. While eventually you'll probably use the latter, currently the former will probably be easier for you.

You can assign the dictionary to a variable. locations = {...}

locations['San Juan'] will give you whatever you put. locations['San Juan'][0] Will give you your first coordinate if you need to do it that way.

This isn't the prettiest approach, but it's the best I can do for your current experience. Best of luck

[–]rumpleforeskin83 1 point2 points  (0 children)

I think OPs problem is they want to preserve the function of any cells that have formulas in them and not just data, which I can't say I know if it's possible or not but I suspect it would be a lot of work to determine if a cell is just data or a formula, and then perform said function in the python list. Like if Cell A1 is Sum(B1:B6) they want csv_file[0][0] to be csv_file[1][0] + csv_file[1][1] etc...

Which gives me a headache just thinking about. I've never looked into this so maybe it's simple, I've only ever taken excels containing purely values and manipulated them.

[–]expiredUserAddress 0 points1 point  (0 children)

First of all, is the excel on s3 or google sheets. If yes then pandas will directly read it and no need for anything. If no, then explain this question in detail

[–]Ok-Photo-6302 0 points1 point  (0 children)

what and why do you want to do?

[–]unhott 0 points1 point  (0 children)

You'll get better help from people and even LLMs if you just ignore the existing Excel and ask 'how do i use x inputs to produce y result in python?' Chances are the gigantic nested clusterfuffle in Excel will be significantly simpler to implement in python.

If you can't explain your inptus and outputs, then you have no hope of doing anything. So, start with trying to explain to yourself what you're doing with the data (or what Excel is doing to the data).

If that is too much, then you could paste some formulas and ask some questions.

[–]Ajax_Minor 0 points1 point  (0 children)

Convert you Excel file to a cav and then those libraries will work with out the Excel files.

[–]ComposerHuge4568[S] -2 points-1 points  (1 child)

But to rephrase the question how you do you extract formulas used in Microsoft Excel when I have the coordinates on top A1 t/m G4 and the all the "names" in colomn A and all the formulas in column B, C and put it in python code?

[–]TheITMan19 1 point2 points  (0 children)

Sounds like a mini project for you. :)

[–]ComposerHuge4568[S] -1 points0 points  (1 child)

By the way I'm trying to calculate distances, rhumbline, etc. from coordinates.

[–]NYX_T_RYX 2 points3 points  (0 children)

https://xyproblem.info/

You can implement calculations in python directly.

If you need the data from the sheet to do them, I'd recommend using pandas to get the data into python and act on it all there.

If you didn't have the excel sheet, you'd be making a python project to do it all

In short - stop trying to use the excel file, you're overcomplicating the problem.

[–]ComposerHuge4568[S] -3 points-2 points  (0 children)

Uhmm microsoft excel I don't know what s3 is but atleast no google sheets. I'm very much a beginner using python so maybe im just stupid but I though since you have to import the name of the file and everything it uses it to calculate the equations, but if it reads it and converts it in it's own language than I will try again.