mercredi 25 février 2015

How to loop through data and print into same column one after another?

This is my first post so sorry if its incorrect.



import xlsxwriter
workbook = xlsxwriter.Workbook('demo.xlsx')
worksheet = workbook.add_worksheet()
worksheet.set_column('A:A', 20)
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'Subjects')

for msg in mbox:
try:
print (msg['subject'])
except:
print("error")

workbook.close()


At the moment i have a heading of Subject in A1. How can i print the msg['subject'] under the heading in A2,A3,A4 and so on.?


I think i have answerd my own question. This is what i did and it worked:



i = 2
for msg in mbox:
try:
worksheet.write('A{}'.format(i), msg['subject']
i = i+1

Aucun commentaire:

Enregistrer un commentaire