write array starting from specific column to new w

2019-07-02 11:55发布

问题:

I am trying to write an array (data = [][]) to a worksheet I will create using xlwt. My question is can I specify a column to start from? I am planning to use a for loop to iterate through the array retrieving the values row by row starting a new line with each row ex: first row starts at C1, next row starts at C2 etc... I have read the documentation and examples but cannot find a clear way to do this. Any help would be greatly appreciated!

回答1:

Something like:

wb = xlwt.Workbook()
ws = wb.add_sheet('Sheet1')
for r, row in enumerate(data):
    for c, col in enumerate(row):
        ws.write(r, 2 + c, label=col)


标签: python xlwt