fromdocx Import Document fromdocx.shared Import inchesdocument=Document () document.add_heading ('Document Title',0) P= Document.add_paragraph ('A Plain paragraph having some') P.add_run ('Bold'). Bold =Truep.add_run ('and some') P.add_run ('Italic.'). Italic =truedocument.add_heading ('Heading, Level 1', level=1) Document.add_paragraph ('Intense Quote', style='Intensequote') Document.add_paragraph ('First item in unordered list', style='Listbullet') Document.add_paragraph ('First item in ordered list', style='Listnumber') Document.add_picture ('Monty-truth.png', Width=inches (1.25)) Table= Document.add_table (rows=1, cols=3) Hdr_cells= table.rows[0].cellshdr_cells[0].text ='Qty'hdr_cells[1].text ='Id'hdr_cells[2].text ='Desc' forIteminchRecordset:row_cells=Table.add_row (). Cells row_cells[0].text =Str (item.qty) row_cells[1].text =Str (item.id) row_cells[2].text =Item.descdocument.add_page_break () document.save ('Demo.docx')
Python's actions on word