with open openpyxl how to wirte to the excel sheets

Solutions on MaxInterview for with open openpyxl how to wirte to the excel sheets by the best coders in the world

showing results for - "with open openpyxl how to wirte to the excel sheets"
Lucia
13 Jul 2016
1# import openpyxl module 
2import openpyxl 
3
4# Call a Workbook() function of openpyxl 
5# to create a new blank Workbook object 
6wb = openpyxl.Workbook() 
7
8sheet = wb.active 
9
10# using sheet object's cell() method. 
11c1 = sheet.cell(row = 1, column = 1) 
12
13# writing values to cells 
14c1.value = "ANKIT"
15
16c2 = sheet.cell(row= 1 , column = 2) 
17c2.value = "RAI"
18
19c3 = sheet['A2'] 
20c3.value = "RAHUL"
21
22c4 = sheet['B2'] 
23c4.value = "RAI"
24
25# Anytime you modify the Workbook object 
26# or its sheets and cells, the spreadsheet 
27# file will not be saved until you call 
28# the save() workbook method. 
29wb.save("C:\\Users\\user\\Desktop\\demo.xlsx") 
30