1
Realizing that it has a lot of repetitive code I decided to automate creating a looping of reading the cells of my excel file.
#row cell fixa para o horario
rows = ts[1].rows
cells = rows[1].cells
#Segunda 7h40min - 8h30min
cell = cells[3]
t1cell13 = cell.paragraphs
t1cell13 = str(t1cell13[0].text.encode("utf-8"))
t1cell13 = unicode(t1cell13, "utf-8")
print t1cell13
w_sheet.write(8,10, t1cell13, style)
a1 = t1cell13
#terça 7h40min - 8h30min
cell = cells[4]
t1cell14 = cell.paragraphs
t1cell14 = str(t1cell14[0].text.encode("utf-8"))
t1cell14 = unicode(t1cell14, "utf-8")
w_sheet.write(9,10, t1cell14), style)
a2 = t1cell14
#Quarta 7h40min - 8h30min
cell = cells[5]
t1cell15 = cell.paragraphs
t1cell15 = str(t1cell15[0].text.encode('utf-8'))
t1cell15 = unicode(t1cell15, "utf-8")
w_sheet.write(t1cell15, style)
a3 = t1cell15
#quinta 7h40min - 8h30min
cell = cells[6]
t1cell16 = cell.paragraphs
print str(t1cell16[0].text.encode('utf-8'))
w_sheet.write(11,10, str(t1cell16[0].text), style)
a4 = str(t1cell16[0].text.encode('utf-8'))
#sexta 7h40min - 8h30min
cell = cells[7]
t1cell17 = cell.paragraphs
print str(t1cell17[0].text.encode('utf-8'))
w_sheet.write(12,10, str(t1cell17[0].text), style)
a5 = str(t1cell17[0].text.encode('utf-8'))
#Sabado 7h40min - 8h30min
cell = cells[8]
t1cell18 = cell.paragraphs
a6 = str(t1cell18[0].text.encode('utf-8'))
Doing so:
#row cell fixa para o horario
rows = ts[1].rows
cells = rows[1].cells
i = 3
j = 8
k = 1
while (i < 9):
cell = cells[(i)]
item = cell.paragraphs
item = str(item[0].text.encode("utf-8"))
item = unicode(item, "utf-8")
i = i+1
while (j < 13):
w_sheet.write((j),10, item, style)
j = j+1
while (k < 7):
a(k) = item
k = k+1
but at the end of the while where I try to put a(k), this not working needed every last while lopping me back: a1 = item a2 = item . . .
If you have another solution option you can also share.
Thank you very much.
I think with
a(k) = item
he’s trying to create a dictionary anyway. That’s what he was going to answer as a solution! + 1– Zuul
Thanks for the quick reply =D no a(k) I can’t tell you if it’s a dictionary. then I will need to use the following way manhasegunda = (a1, A7, A13, A19, A25, A31) so I have return that the a1 variable is not defined. Obs I had tried this way tbm =D
– Murilo Ferro