Skip to main content

Convert html to docx

Project description

htmldocx

Convert html to docx

Dependencies: python-docx & bs4

To install

pip install htmldocx

Usage

Add strings of html to an existing docx.Document object

from docx import Document
from htmldocx import HtmlToDocx

document = Document()
new_parser = HtmlToDocx()
# do stuff to document

html = '<h1>Hello world</h1>'
new_parser.add_html_to_document(html, document)

# do more stuff to document
document.save('your_file_name')

Convert files directly

from htmldocx import HtmlToDocx

new_parser = HtmlToDocx()
new_parser.parse_html_file(input_html_file_path, output_docx_file_path)

Convert files from a string

from htmldocx import HtmlToDocx

new_parser = HtmlToDocx()
docx = new_parser.parse_html_string(input_html_file_string)

Change table styles

Tables are not styled by default. Use the table_style attribute on the parser to set a table style. The style is used for all tables.

from htmldocx import HtmlToDocx

new_parser = HtmlToDocx()
new_parser.table_style = 'Light Shading Accent 4'

To add borders to tables, use the TableGrid style:

new_parser.table_style = 'TableGrid'

Default table styles can be found here: https://python-docx.readthedocs.io/en/latest/user/styles-understanding.html#table-styles-in-default-template

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

htmldocx-0.0.6.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

htmldocx-0.0.6-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file htmldocx-0.0.6.tar.gz.

File metadata

  • Download URL: htmldocx-0.0.6.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.3

File hashes

Hashes for htmldocx-0.0.6.tar.gz
Algorithm Hash digest
SHA256 b4bcec895f86d7a50ffc7133ca24d85c24f3614db2b37d33a30d9d04654a5486
MD5 b49ef80c7317602501624779e1f04961
BLAKE2b-256 8b6191a6b70ee576a4b07310d81efd4c688fe2e6f63ea42ec95b8f1d436b887e

See more details on using hashes here.

File details

Details for the file htmldocx-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: htmldocx-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.3

File hashes

Hashes for htmldocx-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 adf5e95ad8ba8121e606cf138c614de13327a1192a5782acdb4a0abdc23db1b7
MD5 a06a800dfb36a333485b6b6d8f006ab5
BLAKE2b-256 8fdac70fc2ce54c1d1ce7c16f9656589273a6c94cbbc8867b3a512618d977309

See more details on using hashes here.

Supported by

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