I use this code to replace text with HTML text.
// Create Temp. Document
Spire.Doc.Document docHtml = new Spire.Doc.Document();
// Copy Styles and Themes from main document to temp document
doc.CloneDefaultStyleTo(docHtml);
doc.CloneThemesTo(docHtml);
doc.CloneCompatibilityTo(docHtml);
// Get the first section of the main document
Section docSection = (Section)doc.Sections[0];
// Add section to temp document
docHtml.AddSection();
var count = docSection.Paragraphs.Count;
// Get the first paragraph of the main document
Spire.Doc.Documents.Paragraph docParagraph= docSection.Paragraphs[docSection.Paragraphs.Count - 1];
// Make a clone of the main document's paragraph so the styling is copied too
Spire.Doc.Documents.Paragraph newParagraph = (Spire.Doc.Documents.Paragraph)docParagraph.Clone();
// Add the copied paragraph to the section of the temp. document
docHtml.Sections[0].Paragraphs.Add(newParagraph);
// Add the HTML string of the description tot the paragraph
docHtml.Sections[0].Paragraphs[0].AppendHTML(quoteDescription);
// Loop through the appended paragraphs to remove the liune spacing.
foreach (Section htmlSection in docHtml.Sections)
{
for (int i = 0; i < htmlSection.Body.ChildObjects.Count; i++)
{
if (htmlSection.Body.ChildObjects[i].DocumentObjectType == DocumentObjectType.Paragraph)
{
// Disabled this for demonstration
//(htmlSection.Body.ChildObjects[i] as Spire.Doc.Documents.Paragraph).Format.LineSpacing = 8;
}
}
}
// Make the document an Interface Document so we can insert it in the main document
IDocument replaceDoc = docHtml as IDocument;
// Replace the placeholder with the Interface Document
doc.Replace("{{Description}}", replaceDoc, false, true);
There are a few problems:
1. I need to override the line spacing for each paragraph, because otherwise the spacing is way too large. Even though it's correctly set in the Word document. See attachment 1. I don't want to set a static number as line spacing, since the line spacing may vary in the used Word document.
2. I have the replacement text after a label Omschrijving:. When the text is replaced with HTML, there a spacing on the left of the text? See attachment 1
3. The font of the numbered list is not the same as the font in the document. Even though the text after the number is correct.
Attachment 2 is how the replaced text is supposed to look like.