-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexcelExercise.py
79 lines (73 loc) · 2.27 KB
/
excelExercise.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import xlrd
loc = ("configuration/operaciones.xlsx")
def ExecuteSum(num1,num2):
#return int(num1)+int(num2)
try:
valor1 = int(num1)
valor2 = int(num2)
valRetorno =valor1 + valor2
except:
valRetorno = 'Error'
return valRetorno
def ExecuteRest(num1,num2):
try:
valor1 = int(num1)
valor2 = int(num2)
valRetorno =valor1 - valor2
except:
valRetorno = 'Error'
return valRetorno
def ExecuteMult(num1,num2):
try:
valor1 = int(num1)
valor2 = int(num2)
valRetorno =valor1 * valor2
except:
valRetorno = 'Error'
return valRetorno
def ExecuteDiv(num1,num2):
try:
valor1 = int(num1)
valor2 = int(num2)
valRetorno =valor1 / valor2
except:
valRetorno = 'Error'
return valRetorno
functionActions = {0:ExecuteSum,
1:ExecuteRest,
2: ExecuteMult,
3: ExecuteDiv
}
LabelActions = {0:'Suma',
1:'Resta',
2: 'Multiplicación',
3: 'División'
}
# evaluate the sum operation
try:
wb = xlrd.open_workbook(loc)
operation = 0
f= open("Operations.txt","w+")
s_Datos = "============================== OPERACIONES ============================ \n"
f.close()
f= open("Operations.txt","a+")
while operation < 4:
sheet = wb.sheet_by_index(operation)
s_Datos = '====================== Operacion <'+ LabelActions.get(operation)+' > ======================\n'
print ('====================== Operacion <'+ LabelActions.get(operation)+' > ======================' )
# For row 0 and column 0
sheet.cell_value(1, 0)
for i in range(sheet.nrows):
if i == 0:
continue
val1 = sheet.cell_value(i, 0)
val2 = sheet.cell_value(i, 1)
func = functionActions.get(operation)
Calculo = func(val1,val2)
s_Datos = s_Datos + str(Calculo)+" \n"
print (' Row <'+str(i)+'>. Operacion <'+ LabelActions.get(operation)+' > ==>'+str(Calculo) )
f.write(s_Datos)
operation = operation + 1
finally:
wb.__exit__
f.close()