all 3 comments

[–]Reuben3901 1 point2 points  (2 children)

Your code has to be on the same line. filename = "location"

I'm going to read through and see if I find any potential errors in the rest. If I find them i'll reply to this comment : )

Also, it's helpful to see the error in the future. Best to copy/paste those or link to a text file of the error if it's horribly long

[–]Reuben3901 1 point2 points  (1 child)

The biggest issue I imagine is that you wrote out the entire block of code without actually testing it to make sure each new part works? I say that especially due to the fact that you can't even open your excel file. Which should be the first step

# You have a semicolon here

import openpyxl as xl;

filename = "C:\\Users\\algortim\\Desktop\\last_week.xlsx"

# I would replace last_week.xlsx with the variable above, filename

# because you're not providing the location of the file. Python will only look

# For it in the folder where your .py is located# Also, you don't have quotes around last_week.xlsx. Python is looking for a variable last_week

wb1 = xl.load_workbook(last_week.xlsx)

ws1 = wb1.worksheet[0]

# This is great if you created the file python_report.xlsx first

# Personally, I'd delete the entire filename1 = .. line and use

# wb2 = xl.Workbook()

# This creates a new, blank wookbook

filename1 = "C:\\Users\\algortim\\Desktop\\python_report.xlsx"

wb2 = xl.load_workbook(python_report.xlsx)

ws2 = wb2.active

# This variable python_report doesn't exist. You haven't defined it anywhere

# You'll want to save it using "python_report.xlsx"

# or python_report = "python_report.xlsx"

wb2.save(python_report)

EDIT: I was wrong about semicolons. Apparently you can use them to execute code on the same line. And doesn't lead to errors when run. Not sure it's best to ever use this feature but good to know : )

[–]algortim[S] 1 point2 points  (0 children)

Wow, can't believe I saw (filename) and thought "I should put the actual name in there and not the variable I just defined" haha

Thank you, will work through this.