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 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.2.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.2-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wordexceltools-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 f31973f195e1c02e6074e0b07015fb0abb395149a4cefca42fa0de5f38903fe8
MD5 d89aefd814c1b1aeb7bb8461b85b7cc4
BLAKE2b-256 0d24b4f129e6f3e80d18d423966288dec9b0f45196baabbf06ebe5268f32a793

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wordexceltools-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ea25cb22b556bdb1a1d946f8c546d3641f0ae9945176b7fef40528be271c7b14
MD5 5e3cd4f5d4ae40477966221056fb4baf
BLAKE2b-256 9cf6fe6c3ae721a207a0a2ab348a09e72e8eda582623899c8c0bd6c8d92edda2

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