Reputation: 179
I would like to write a program which paste each element of array (separated by commas) into different column in excel. My code works, but numbers are stored as text not as number. How can I fix it?
from xlwt import Workbook
wb = Workbook()
sheet1 = wb.add_sheet('Sheet 1')
my_string = ["aaaaa,123,532","bbbbb,345,678"]
tab=[]
for y in my_string:
z=y.split(",")
tab.append(z)
for a in range(0,len(tab)):
for b in range(0,len(tab[a])):
print (tab[a][b])
sheet1.write(a,b,tab[a][b])
wb.save('exxa.xls')
Upvotes: 0
Views: 190
Reputation: 4159
Convert the strings to numbers:
my_string = ["aaaaa,123,532","bbbbb,345,678"]
tab=[]
for y in my_string:
z=y.split(",")
z[1] = int(z[1])
z[2] = int(z[2])
tab.append(z)
Upvotes: 1