-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetUp_Mode.py
62 lines (41 loc) · 1.66 KB
/
SetUp_Mode.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import openpyxl
import subprocess
# read value from a cell in excel file
def get_value_excel(filename, cellname):
wb = openpyxl.load_workbook(filename)
Sheet1 = wb['Sheet1']
wb.close()
return Sheet1[cellname].value
# write value to a specific cell
def update_value_excel(filename, cellname, value):
wb = openpyxl.load_workbook(filename)
Sheet1 = wb['Sheet1']
Sheet1[cellname].value = value
wb.close()
wb.save(filename)
# Force kill Excel if running to avoid conflict
s = subprocess.check_output('tasklist', shell=False)
if b"EXCEL.EXE" in s:
subprocess.call(['taskkill', '/F', '/IM', 'excel.exe'])
# Choose window state match cases
for index in range(8):
filename = 'SetUp_Mode.xlsx'
Window_cell = 'D' + str(index + 2)
Mode_cell = 'G' + str(index + 2)
Light_cell_value = get_value_excel(filename, 'A' + str(index + 2))
Rain_cell_value = get_value_excel(filename, 'B' + str(index + 2))
Sound_cell_value = get_value_excel(filename, 'C' + str(index + 2))
print(str(index + 1) + '. ' + Light_cell_value + ' + ' + Rain_cell_value + ' + ' +
Sound_cell_value + ', đóng hay mở cửa?(1: đóng, 2:mở):')
# Process cases
Choose_Window_State = input()
if Choose_Window_State == '1':
update_value_excel(filename, Window_cell, 'đóng cửa')
update_value_excel(filename, Mode_cell, 'gạt XUỐNG')
continue
if Choose_Window_State == '2':
update_value_excel(filename, Window_cell, 'mở cửa')
update_value_excel(filename, Mode_cell, 'gạt LÊN')
print('Mở excel file lên nào!')
# Open excel file
subprocess.Popen(['start', filename], shell=True)