create_custom_bill_doc.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from docx import Document
  2. from docx.shared import Inches
  3. import time
  4. 'https://python-docx.readthedocs.io/en/latest/user/text.html'
  5. def create_custome_doc_file():
  6. '''
  7. :return: Bill as Doc file
  8. '''
  9. document = Document()
  10. document.add_heading('Document Title', 0)
  11. p = document.add_paragraph('A plain paragraph having some ')
  12. p.add_run('bold').bold = True
  13. p.add_run(' and some ')
  14. p.add_run('italic.').italic = True
  15. document.add_heading('Heading, level 1', level=1)
  16. document.add_paragraph('Intense quote', style='Intense Quote')
  17. document.add_paragraph(
  18. 'first item in unordered list', style='List Bullet'
  19. )
  20. document.add_paragraph(
  21. 'first item in ordered list', style='List Number'
  22. )
  23. records = (
  24. (3, '101', 'Spam'),
  25. (7, '422', 'Eggs'),
  26. (4, '631', 'Spam, spam, eggs, and spam')
  27. )
  28. table = document.add_table(rows=1, cols=3)
  29. hdr_cells = table.rows[0].cells
  30. hdr_cells[0].text = 'Qty'
  31. hdr_cells[1].text = 'Id'
  32. hdr_cells[2].text = 'Desc'
  33. for qty, id, desc in records:
  34. row_cells = table.add_row().cells
  35. row_cells[0].text = str(qty)
  36. row_cells[1].text = id
  37. row_cells[2].text = desc
  38. document.add_page_break()
  39. doc_output_path = r'C:\Users\Danny\Desktop\ssd wichtige dinge D\Tools\fast_excel_to_bill\test_folder' + r'\doc_test_{}.docx'.format(time.strftime("%Y-%m-%d_H%H-M%M"))
  40. document.save(doc_output_path)