I have two sheets in one excel file. And I want to read the two values from the two excel sheets.
SO I try it like this:
JavaScript
x
17
17
1
import openpyxl
2
3
4
path = "./docs/hoi.xlsx"
5
6
7
wb_obj = openpyxl.load_workbook(path, data_only=True)
8
9
sheet_names = [' Overzicht Noord ', 'Overzicht Midden']
10
11
for i in sheet_names:
12
sheet_obj = wb_obj[i]
13
cell_obj = sheet_obj.cell(row = 6, column = 8).value
14
15
print(cell_obj)
16
17
But it only returns one value from one sheet. And not the two values from the two sheets.
My question is: how to return the two values from the two sheets?
Advertisement
Answer
You are assigning it to the same variable – cell_obj
. Please move the print
inside the loop.