-
Notifications
You must be signed in to change notification settings - Fork 1
/
excel.py
31 lines (25 loc) · 1013 Bytes
/
excel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pandas as pd
class ExcelLoader:
def __init__(self, file_path):
self.file_path = file_path
self.excel_dataframes = self._load_excel_sheets()
def _load_excel_sheets(self):
# Read all sheets into a dictionary of dataframes
return pd.read_excel(self.file_path, sheet_name=None)
def display_sheets(self):
# Access each dataframe by sheet name dynamically
for sheet_name, df in self.excel_dataframes.items():
print(f"Sheet Name: {sheet_name}")
print(df)
print("-" * 40)
def print_loaded_sheets(self):
# Print the names of the loaded sheets
sheet_names = list(self.excel_dataframes.keys())
print(f"Loaded sheets: {', '.join(sheet_names)}")
if __name__ == "__main__":
# Example usage
excel_file_path = "run12.xlsx"
excel_loader = ExcelLoader(excel_file_path)
excel_loader.display_sheets()
# New method to print loaded sheets
excel_loader.print_loaded_sheets()