Skip to main content

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

Project description

WordExcelTools

A tool for quickly generating word documents based on 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.0.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.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wordexceltools-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 dd34765243b42085e93c4101657c7c74c48505657b0c7a515200d3ac160bfa1f
MD5 25efe439016e2aa20ab228923b6f9f1a
BLAKE2b-256 58bfbfab1e1fbc8f322c355a4830573105025a775a8cfc35a6fabbc5d08f61fd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wordexceltools-1.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7a0b7c598b67bea5974cb4c42b9f5213cd69a9f7adaac457a5c6355fe4de55b
MD5 333f871a7596202d2da3a393f9bebcad
BLAKE2b-256 502b60735762d6192892534d956c69c9003f3dadb9d439b1f717740127d5f093

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