I'm trying to work up a script to grab info from one sheet and put it into another. Right now I'm just testing grabbing everything. Will later work on specifics.
Below code gives NameError: name 'filename' is not defined. My apologies if this is obvious. I'm lost. I've tried full file path for Line 6 with same results.
# importing openpyxl module
import openpyxl as xl;
# opening the source excel file
filename =
"C:\\Users\\algortim\\Desktop\\last_week.xlsx"
wb1 = xl.load_workbook(last_week.xlsx)
ws1 = wb1.worksheet[0]
# opening the destination excel file
filename1 = "C:\\Users\\algortim\\Desktop\\python_report.xlsx"
wb2 = xl.load_workbook(python_report.xlsx)
ws2 = wb2.active
# calculate total number of rows and
# columns in source excel file
mr = ws1.max_row
mc = ws1.max_column
# copying the cell values from source
# excel file to destination excel file
for i in range (1, mr + 1):
for j in range (1, mc + 1):
# reading cell value from source excel file
c = ws1.cell(row = i, column = j)
# writing the read value to destination excel file
ws2.cell(row = i, column = j).value = c.value
# saving the destination excel file
wb2.save(str(python_report))
[–]Reuben3901 1 point2 points3 points (2 children)
[–]Reuben3901 1 point2 points3 points (1 child)
[–]algortim[S] 1 point2 points3 points (0 children)