-
Notifications
You must be signed in to change notification settings - Fork 1
/
Excel work.py
35 lines (30 loc) · 1.01 KB
/
Excel work.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
32
33
34
35
import json
import docx
import sys
from openpyxl import load_workbook
# Replace 'your_file.xlsx' with the path to your Excel file.
data_received = sys.argv[1]
workbook = load_workbook(data_received)
sheet = workbook.active
data = {}
first_data_point = ""
# You can also specify a specific sheet within the Excel workbook:
# excel_file = pd.read_excel('your_file.xlsx', sheet_name='Sheet1')
for column in sheet.iter_cols():
# 'row' is a tuple representing one row of data.
# You can access the columns by index, for example:
i = 0
for index, cell in enumerate(column):
column_value = cell.value # Access the cell value.
if (i == 0):
first_data_point = column_value
i += 1
else:
if first_data_point in data:
data[first_data_point].append(column_value)
else:
data[first_data_point] = [column_value]
print(data)
filename = "data.json"
with open(filename, "w") as json_file:
json.dump(data, json_file, indent=4)