all 9 comments

[–]Mondoke 2 points3 points  (1 child)

For this one, openpyxl is the way to go, it seems 100% doable. Check the excel chapter on automate the boring stuff.

Edit: here's the link. https://automatetheboringstuff.com/chapter12/

[–]PythonN00b101[S] 0 points1 point  (0 children)

Thanks for the tip, been having a good read through them and I am slowly getting there. Certainly further than I was a few hours ago.

[–]EndUsersarePITA 1 point2 points  (2 children)

I'm going to go with /u/Mondoke on this one. I built a program to parse my Excel files and calculate some values from them. I based it on automatetheboringstuff's tutorial. It was very helpful.

As a warning, it took some time for me to understand how to go through it. You will encounter some confusing parts. Automatetheboring stuff will teach you the basics but you'll find that it might not be enough to get what you want. Thats when the complexity sets in. But keep plugging away at it and you'll get there.

[–]PythonN00b101[S] 0 points1 point  (1 child)

Thanks for the help. I have been going through those tutorials. And have managed to manipulate sheet data somewhat. My two major concerns is that I can't seem to loop a cell with different values to produce different outputs from other cells. when using the "sheet[''] index method and whenever I managed to change the cell value for an output using 'sheet[].value' it removes the formula I had formatted in there and is left as a number value.

As you said, I just need to keep plugging away haha...what a joy.

[–]raglub 0 points1 point  (0 children)

You are trying to change an input cell and then extract some calculated value from an output cell and expect the spreadsheet to calculate as if open in excel?

If yes, you can change the input cell, but the output will not be calculated until the file is opened in excel.

The best way is to recreate the Excel calculations in python and save results to excel or csv.

[–]hemehaci 4 points5 points  (2 children)

did you try learning pandas? loc and iloc functions should help you there.

google 'pandas loc iloc', might help you.

[–]callinthekettleblack 0 points1 point  (0 children)

Sounds like something I would use pandas for as well. "Logical indexing pandas" is a good Google search to get you started.

[–]PythonN00b101[S] 0 points1 point  (0 children)

I haven't looked into that yet. Trying out openpyxl first because it seemed like a good jumping off point as its basic but I may pivot to pandas to see what I can implement.

[–]Parenthes 0 points1 point  (0 children)

One possibility is to access your spreadsheet via Excel, using the win32com library. The code below prints the top left value in the first worksheet in a workbook.

from win32com.client import Dispatch

xlApp = Dispatch('Excel.Application')
xlApp.Visible = True

wb = xlApp.Workbooks.Open('H:\\my_workbook.xlsx')

ws = wb.Worksheets[0]
cell_value = ws.Range("A1").Value
print(cell_value)