forked from jabahum/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_docx.py
More file actions
60 lines (48 loc) · 1.33 KB
/
Copy pathwrite_docx.py
File metadata and controls
60 lines (48 loc) · 1.33 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
57
58
59
60
from docx import Document
from docx.shared import Inches
document = Document()
document.add_heading('Document Title', 0)
p = document.add_paragraph('A plain paragraph having some ')
p.add_run('bold').bold = True
p.add_run(' and some ')
p.add_run('italic.').italic = True
document.add_heading('Heading, level 1', level=1)
document.add_paragraph('Intense quote', style='Intense Quote')
document.add_paragraph(
'first item in unordered list', style='List Bullet'
)
document.add_paragraph(
'first item in ordered list', style='List Number'
)
document.add_picture('C:\\Users\\soumi\\Pictures\\application.jpg', width=Inches(1.25))
recordset = [
{
"id" : 1,
"qty": 2,
"desc": "New item"
},
{
"id" : 2,
"qty": 2,
"desc": "New item"
},
{
"id" : 3,
"qty": 2,
"desc": "New item"
}
]
print(recordset[0]['id'])
table = document.add_table(rows=1, cols=3)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Id'
hdr_cells[1].text = 'Quantity'
hdr_cells[2].text = 'Description'
for item in recordset:
#print(item)
row_cells = table.add_row().cells
row_cells[0].text = item['id']
row_cells[1].text = item['qty']
row_cells[2].text = item['desc']
document.add_page_break()
document.save('simple.docx')