Hi,
I am trying to print numbers in a serial in Excel worksheet. My worksheet range is [‘A1:J10’]. At present range is something like this.
1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
---|---|---|---|---|---|---|---|---|---|
2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 |
4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 |
5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 |
I want it in below manner.
1 | 6 | 11 | 16 | 21 | 26 | 31 | 36 | 41 | 46 |
---|---|---|---|---|---|---|---|---|---|
2 | 7 | 12 | 17 | 22 | 27 | 32 | 37 | 42 | 47 |
3 | 8 | 13 | 18 | 23 | 28 | 33 | 38 | 43 | 48 |
4 | 9 | 14 | 19 | 24 | 29 | 34 | 39 | 44 | 49 |
5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 |
I am not able to understand how do I do this. Not looking for exact answers, however can anyone please guide me how I should proceed.
import openpyxl
wbkName = r’\AA\AA\AA\AA\Python Chart Data.xlsx’# Please change path
wbk = openpyxl.load_workbook(wbkName)
#This loop is used to clear contents of worksheets
for wks in wbk.worksheets:
for row in wks[‘A1:J10’]:
for cell in row:
cell.value = None #
for wks in wbk.worksheets:# This will write for all the worksheets in workbook
for myRow in range(1, 6):# 6 will give results till row 5 not 6
for myCol in range(1,11):# 11 will give data till column 10
wks.cell(row=myRow, column=myCol).value = myRow
wbk.save(wbkName)
wbk.close ()