1from openpyxl import Workbook
2
3row = 1
4wb = Workbook()
5wb['Sheet'].title = "Report of Automation"
6sh1 = wb.active
7sh1['A1'].value = 'Name'
8sh1['B1'].value = 'Status'
9sh1['A2'].value = 'Python'
10sh1['B2'].value = 'Avtive'
11sh1['C1'].value = row
12sh1['C'+str(row)].value = 'test'
13
14for a in range(5):
15 sh1['A'+str(a+1)].value = a
16
17wb.save("FinalReport.xlsx")
1from openpyxl import Workbook
2
3filename = 'Testwriteexcel.xlsx'
4sheettitle = 'Sheetname'
5
6wb = Workbook()
7wb['Sheet'].title = sheettitle
8sh1 = wb.active
9sh1['A1'].value = 'Numbers'
10sh1['B1'].value = 'Sqares'
11sh1['C1'].value = 'Column 3'
12
13for n in range(1, 1+10):
14 sh1[f'A{1+n}'].value = n
15 sh1[f'B{1+n}'].value = n**2
16
17try:
18 wb.save(filename)
19except PermissionError:
20 print('File might be opened, please close it before writing')