forked from powerexploit/Awesome-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcel.py
More file actions
56 lines (44 loc) · 1.16 KB
/
Copy pathexcel.py
File metadata and controls
56 lines (44 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
In this script we're going to create a simple excel file with 3(Three) columns
Name | Age | Gender
"""
# xlwt module helps make a new excel file
import xlwt
# create a dictionary with information
DATA_ = {
'Person1' : {
'Name' : 'Bill Gates',
'Age' : 63,
'Gender' : 'Male'
},
'Person2' : {
'Name' : 'Sheryl Sandberg',
'Age' : 50,
'Gender' : 'Female'
},
'Person3' : {
'Name' : 'Tim Cook',
'Age' : 58,
'Gender' : 'Male'
},
}
# first create a new workbook
workbook = xlwt.Workbook()
# add a new sheet to the workbook
sheet = workbook.add_sheet('Sheet1')
# create columns
sheet.write(0,0,'Name')
sheet.write(0,1,'Age')
sheet.write(0,2,'Gender')
# we will keep counter running until we loop through all the persons inside DATA_
counter = 1
# now lets get the details from the DATA_ dict and insert them into our excel sheet
for k, v in DATA_.items():
sheet.write(counter, 0, v['Name'])
sheet.write(counter, 1, v['Age'])
sheet.write(counter, 2, v['Gender'])
# now increment the counter each time
# this will make sure that information are added on new line for each person
counter += 1
# time to save the workbook
workbook.save('details.xls')