Skip to content
Advertisement

How to read values from multiple sheets in excel with openpyxl

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:

import openpyxl


path = "./docs/hoi.xlsx"


wb_obj = openpyxl.load_workbook(path, data_only=True)

sheet_names = [' Overzicht Noord ', 'Overzicht Midden']

for i in sheet_names:     
    sheet_obj = wb_obj[i]
    cell_obj = sheet_obj.cell(row = 6, column = 8).value

print(cell_obj)

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.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement