You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have a web application that uses TinyMCE Editor where users can add Rich Text content which is saved as HTML. I'm generating a Word.docx from all content entered by the users from the web form. Only some of the content is HTML/Rich Text. I'm using the Html2OpenXml library to inject the HTML into parts of the Word.docx file. The issue I'm running into is that a basic ordered Number List with nested Bulleted List which only outputs with incremented numbers, not with nested bullets. I've tested with this basic HTML.
The output comes out like this. FYI, the sample I'm showing comes out nested with correct with spacing, just doesn't show bullets.
1.) Number Parent Item 1
1.) Bullet Sub Item 1-1
2.) Bullet Sub Item 1-2
2.) Number Parent Item 2
1.) Bullet Sub Item 2-1
2.) Bullet Sub Item 2-2
<div>
<ol>
<li>Number Parent Item 1
<ul>
<li>Bullet Sub Item 1-1</li>
<li>Bullet Sub Item 2-1</li>
</ul>
</li>
<li>Number Parent Item 2
<ul>
<li>Bullet Sub Item 2-1</li>
<li>Bullet Sub Item 2-2</li>
</ul>
</li>
</ol>
</div>
Here is the code I'm using.
private List<Paragraph> ConvertHtmlToOpenXML(string htmlText)
{
// Must return at least 1 paragraph
if (string.IsNullOrEmpty(htmlText))
{
List<Paragraph> paragraphs = new List<Paragraph>();
paragraphs.Add(new Paragraph());
return paragraphs;
}
// Temporarily create new document for HTML conversion and then retrieve the generated paragraphs and
// append to original document.
using (var tmpGeneratedDocument = new System.IO.MemoryStream())
{
var tmpPackage = WordprocessingDocument.Create(tmpGeneratedDocument, WordprocessingDocumentType.Document);
var tmpMainDocumentPart1 = tmpPackage.MainDocumentPart;
if (tmpMainDocumentPart1 == null)
{
tmpMainDocumentPart1 = tmpPackage.AddMainDocumentPart();
new Document(new Body()).Save(tmpMainDocumentPart1);
}
var htmlConverter = new HtmlConverter(tmpMainDocumentPart1);
// ParseHtml will automatically append to temp document
htmlConverter.ParseHtml(htmlText);
tmpMainDocumentPart1.Document.Save();
tmpPackage.Close();
tmpGeneratedDocument.Close();
// Return parsed HTML paragraphs
return tmpMainDocumentPart1.Document.Body.Descendants<Paragraph>().ToList();
}
}
The text was updated successfully, but these errors were encountered:
Hi,
I have a web application that uses TinyMCE Editor where users can add Rich Text content which is saved as HTML. I'm generating a Word.docx from all content entered by the users from the web form. Only some of the content is HTML/Rich Text. I'm using the Html2OpenXml library to inject the HTML into parts of the Word.docx file. The issue I'm running into is that a basic ordered Number List with nested Bulleted List which only outputs with incremented numbers, not with nested bullets. I've tested with this basic HTML.
The output comes out like this. FYI, the sample I'm showing comes out nested with correct with spacing, just doesn't show bullets.
1.) Number Parent Item 1
1.) Bullet Sub Item 1-1
2.) Bullet Sub Item 1-2
2.) Number Parent Item 2
1.) Bullet Sub Item 2-1
2.) Bullet Sub Item 2-2
Here is the code I'm using.
The text was updated successfully, but these errors were encountered: