html2docx icon indicating copy to clipboard operation
html2docx copied to clipboard

Underline not converting into docx

Open jacovanderlaan opened this issue 1 year ago • 2 comments

Hi there,

The html2doc module works perfect for me, manu thanks for it. There is just one issue I do not get to work and that is the conversion of italic. Below is a HTML section with text-decoration:underline. Any idee why this is not converting into a underline property in python-docx?

Thx!

jaco

BDV:

jacovanderlaan avatar Apr 12 '24 12:04 jacovanderlaan

Hello! Is your question regarding italics or underlining? I want to improve this functionality. If you're referring to underlining, based on my tests, it works as expected. I can provide you with a code example that might help! Let me know how I can assist further. from docx import Document from htmldocx import HtmlToDocx

document = Document() html_parser = HtmlToDocx()

html_content = '''

Underline Text Example

This is a sample text with underlined words.

Here is another line with multiple underlined words in a sentence.

'''

html_parser.add_html_to_document(html_content, document) document.save('output_with_underline.docx') print("HTML to DOCX conversion complete!")

cyy-2024 avatar Oct 23 '24 15:10 cyy-2024

you can try the code below!

from docx import Document from htmldocx import HtmlToDocx

document = Document() html_parser = HtmlToDocx()

html_content = '''

Underline and Italic Text Example

This is underlined and italic text.

Here is a combination of underlined and italic text.

'''

html_parser.add_html_to_document(html_content, document) document.save('output_with_underline.docx') print("HTML to DOCX conversion complete!")

cyy-2024 avatar Oct 23 '24 15:10 cyy-2024