-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadexcel.py
26 lines (24 loc) · 957 Bytes
/
readexcel.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
import openpyxl
def read_excel_to_dict(file_path):
try:
# Load the Excel workbook
workbook = openpyxl.load_workbook(file_path)
# Select the first sheet (you may need to modify this if your data is in a different sheet)
sheet = workbook.active
# Create a dictionary from the first two columns
result_dict = {}
for row in sheet.iter_rows(min_row=1, max_col=2, values_only=True):
value_list = []
key, value = row
value_list.append(key)
if value == None:
value_list.append('')
else:
value_list.append(value)
result_dict[key] = value_list
return result_dict
except Exception as e:
print(f"An error occurred: {e}")
return None
excel_file_path = 'C:/Users/SHHEKO/Downloads/datatest.xlsx'
result_dictionary = read_excel_to_dict(excel_file_path)