Skip to main content

A tool for quickly generating word documents based on python-docx and openpyxl.

Project description

WordExcelTools

A tool for quickly generating word documents based on python-docx and openpyxl

Install

pip install wordexceltools

Main Functions

1. add_custom_heading(document, level, text)
2. add_custom_paragraph(document, text, style=None)
3. add_custom_table(document, row_count, column_count, style="Table Grid", font_size=10.5, spacing_before=0)
4. add_figure_caption(document, caption_text)
5. add_indented_paragraph(document, text)
6. add_ordered_list(document, items, index_style='number', indentation=1)
7. add_table_caption(document, caption_text)
8. docxinitial(doc, text_font_type='宋体', text_font_size=12, text_font_line_spacing=30, text_header='Header', text_footer='Footer')
9. get_column_keyword_count(sheet, column_name, keyword)
10. get_column_len(sheet, column_name)
11. get_column_list(sheet, column_name)
12. get_column_str_custom(sheet, column_name, separator='、', end_mark='。')
13. get_columns_keyword_counts(sheet, platform_prefix='prefix', result_suffix='suffix')
14. get_platform_results(list_test_objs)
15. get_section_number(paragraph_text)
16. get_sheet(workbook, sheet_index)
17. get_sheet_cell_date_value(sheet, row, column)
18. get_sheet_cell_value(sheet, row, column)
19. get_sheet_name(sheet_data, sheet_index)
20. get_sheets_data(source_excel)
21. get_table_cell_text(table, row_index, column_index)
22. merge_cells(table, start_row, start_column, end_row, end_column)
23. merge_cells_by_column(table, column_index)
24. set_number_to_roman(number)
25. set_table_alignment(table, start_row=None, start_column=None, end_row=None, end_column=None, horizontal_alignment=WD_ALIGN_PARAGRAPH.CENTER, vertical_alignment=WD_ALIGN_PARAGRAPH.CENTER)
26. set_table_cell_text(table, row_index, column_index, text)
27. set_table_style(table, font_size=10.5, spacing_before=0)
28. setsectionformat(doc)

Example

from docx import Document
import openpyxl
import wordexceltools

soucrce_excel = "./test.xlsx"
result_docx = "./test.docx"

doc = Document()
wb_source = openpyxl.load_workbook(soucrce_excel, data_only=True)

# get sheets data
sheet_data = wordexceltools.get_sheets_data(soucrce_excel)

# get 1st sheet object
sheet_0 = wordexceltools.get_sheet(wb_source, 0)

# get 1st sheet name
sheet_0_name = wordexceltools.get_sheet_name(sheet_data, 0)

# get sheet cell value
test_cell = wordexceltools.get_sheet_cell_value(sheet_0, 2, 3)

# add title
wordexceltools.add_custom_heading(document=doc, level=1, text=sheet_0_name)

# add paragraph
wordexceltools.add_custom_paragraph(document=doc, text=test_cell)

doc.save(result_docx)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wordexceltools-1.0.3.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wordexceltools-1.0.3-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file wordexceltools-1.0.3.tar.gz.

File metadata

  • Download URL: wordexceltools-1.0.3.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for wordexceltools-1.0.3.tar.gz
Algorithm Hash digest
SHA256 5aed3ac7389fa578f6cd767435fb43af103cfeb7b33450baaca50da2783c2feb
MD5 37a6de4a8ebf30fac647945f2a97ae6a
BLAKE2b-256 8c149b29d8ee4c41c6b9d3df5bbb232cf4b325e4c84348c0d6df5d2d109155b6

See more details on using hashes here.

File details

Details for the file wordexceltools-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: wordexceltools-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for wordexceltools-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b638aecc89f17a34bbbef9bbb4f41b0e7651146b5a7214cacddcd025bd5d84e0
MD5 863ebd5346613d16a6c1b2f6938bf235
BLAKE2b-256 bb113494572f77524ec3da5a0bfe9cffb979f194417caaaf2ea32b5a0318f855

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page