2

I was wondering if anybody knew how to iterate through letters in excel with python using the module xlsxwriter. I want to put thing A every 1st, 4th, and 7th column and so forth. Thing B every 2nd, 5th, and 8th column. Thing C at every 3rd, 6th, 9th column. Each row down will have different values. That is the best way I can describe it.

import xlsxwriter

workbook = xlsxwriter.Workbook('myfile.xlsx')
worksheet = workbook.add_worksheet()
x = 1

worksheet.write('A1', 'The value of A goes here')
worksheet.write('B1', 'The value of B goes here')
worksheet.write('C1', 'The value of C goes here')

for row in data:
     worksheet.write('A' + str(x), valueA)
     worksheet.write('B' + str(x), valueB)
     worksheet.write('C' + str(x), valueC)
     x += 1

workbook.close()

Just imagine each row has its own set inside data, and value A B C changes for each increment of x.

How do I put my value A at A, D, G... value B at B,E,H... value C at every C, F, I ... and so forth? I'm not sure how to iterate through that :( Can somebody help?

Kenny Truong
  • 615
  • 1
  • 7
  • 12
  • possible duplicate of [How do I iterate through the alphabet in Python, Please?](http://stackoverflow.com/questions/17182656/how-do-i-iterate-through-the-alphabet-in-python-please) – Richard Sep 18 '15 at 00:16
  • Look here : http://stackoverflow.com/questions/17182656/how-do-i-iterate-through-the-alphabet-in-python-please – Richard Sep 18 '15 at 00:16
  • What are you values? Where is valueA, valueB, ... come from? – Richard Sep 18 '15 at 00:17
  • Just in case it is part of the confusion: you don't have to use 'A1' notation in XlsxWriter. You can use numeric (row, col) values instead. That would be easier to specify for the non-contiguous data you want to write. – jmcnamara Sep 18 '15 at 00:24
  • thank you! I figured it out! – Kenny Truong Sep 18 '15 at 04:24

0 Answers0