We are currently experimenting with using Spire.Doc on Python and are probably going to request a trial.
We did face an issue trying to convert HTML to Word (2019 Docx)
For many documents we have, it does work. However, for some it seems to fail and we are unsure why.
Below I added the code we are using:
- Code: Select all
# Create an object of the Document class
document = Document()
# Add a section to the document
sec = document.AddSection()
# Add a paragraph to the section
paragraph = sec.AddParagraph()
# Specify the HTML string
htmlString = f"""
<html>
<body>
{protocol["HTML"]}
</body>
</html>
"""
# Append the HTML string to the paragraph
paragraph.AppendHTML(htmlString)
# Save the result document
document.SaveToFile(outputFile, FileFormat.Docx2019)
document.Close()
With protocol["HTML"] usually working, with the exception of a few that give us the following Exception:
- Code: Select all
Unhandled Exception: System.InvalidOperationException: InvalidOperation_EmptyStack
at System.Collections.Generic.Stack`1.ThrowForEmptyStack() + 0x33
at System.Collections.Generic.Stack`1.Pop() + 0x42
at sprkyl.spra(XmlNode, XmlNode) + 0xb4
at sprkyl.spran(XmlNode) + 0x1df
at sprkyl.spra(XmlNodeList) + 0xc3
at sprkyl.spran(XmlNode) + 0x1bff
at sprkyl.spra(XmlNodeList) + 0xc3
at sprkyl.sprac(XmlNode) + 0xe53
at sprkyl.spran(XmlNode) + 0x1ed0
at sprkyl.spra(XmlNodeList) + 0xc3
at sprkyl.sprap(XmlNode) + 0x2e
at sprkyl.spran(XmlNode) + 0x1a61
at sprkyl.spra(XmlNodeList) + 0xc3
at sprkyl.sprap(XmlNode) + 0x2e
at sprkyl.spran(XmlNode) + 0x1a61
at sprkyl.spra(XmlNodeList) + 0xc3
at sprkyl.sprap(XmlNode) + 0x2e
at sprkyl.spran(XmlNode) + 0x1a61
at sprkyl.spra(XmlNodeList) + 0xc3
at sprkyl.sprdh1(IBody, String, Int32, Int32) + 0x15cd
at Spire.Doc.Documents.Paragraph.AppendHTML(String) + 0x255
at Spire.Doc.AOT.NLParagraph.Paragraph_AppendHTML(IntPtr, IntPtr) + 0x58
The protocol["HTML"] that we are adding in this case, is the following:
- Code: Select all
<p style="font-size: medium; font-weight: normal;">Versienummer : 1<br>Versiedatum : Oktober 2017</p>
<h1 style="text-align: center;">Intra-orale opname</h1><hr>
<ul>
<li><p>Opnamen worden alleen vervaardigd op indicatie van de tandarts.</p></li>
<li><p>De volgende personen zijn gerechtigd tot het maken van opnamen:
<br><em><u>Klik hier als u tekst wilt invoeren.</u></em></p></li>
<li><p>Vraag naar zwangerschap, indien zwanger overleg met de tandarts in verband met urgentie van diagnose en behandeling.</p></li>
<li><p>Informeer de patiënt over de reden voor het maken van een foto.</p></li>
<li><p>In geval van twijfel over de te volgen opnameprocedure of andere onvoorziene situaties wordt contact opgenomen met de tandarts.</p></li>
<li>
<p>Bij twijfel aan de goede werking van het röntgentoestel wordt de opname uitgesteld en contact opgenomen met de toezichthoudend stralingsdeskundige.</p></li></ul>
<p>
<ul>
<li><p>Geef de patiënt instructie over goede steun van het hoofd om beweging te voorkomen.</p></li>
<li><p>Schildklierkraag hoog tegen kin positioneren om schildklier te beschermen.</p></li>
<li><p>Laat de richtapparatuur zien en vertel om hoeveel opnamen het gaat.</p></li>
<li><p>Trek handschoenen aan.</p></li>
<li><p>Houdt met de ene hand de mondhoek opzij om goed zicht te hebben en plaats met de andere hand de richtapparatuur.</p></li>
<li><p>Vraag de patiënt om dicht te bijten en gebruik zonodig een wattenrol om de apparatuur te stabiliseren.</p></li>
<li>
<p>Controleer belichtingstijd. </p></li>
<li>
<p>Richt de röntgenbuis in het juiste horizontale vlak en in een correcte verticale hoek.</p></li>
<li>
<p>Loop naar de timer, en ga achter de muur staan.</p></li>
<li>
<p>Houdt de knop zo lang ingedrukt tot de piep over is gegaan.</p></li>
<li>
<p>Haal de foto en richtapparatuur uit de mond en leg deze op de tray.</p></li>
<li>
<p>Breng de röntgenbuis weer terug op zijn plaats.</p></li></ul>
<p>
<ul>
<li>
<p>De gemaakte opnamen worden beoordeeld door de tandarts, in eerste instantie op kwaliteit, vervolgens ook op diagnostische inhoud. Opnamen worden direct na het vervaardigen toegevoegd aan het patiëntendossier.</p></li>
<li>
<p>De diagnostische kwaliteit van de opnamen kan worden ingedeeld in drie categorieën. Minimaal 70% van de opnamen moet zonder meer voldoen aan de gebruikelijke kwaliteitseisen. Er moet worden gestreefd naar zo min mogelijk opnamen die om kwaliteitsredenen moeten worden overgemaakt; het aantal opnamen in deze categorie mag in elk geval niet meer zijn dan 10%.</p></li></ul>
We are uncertain if this is a faulty HTML, or that there is some other issue. Cause in most cases, it works. We also tried removing the ö character, but without success.
Thanks for helping us out!