Hi,
Thanks for the wonderful HtmlConverter code. I'm using the version 1.5 in my application to convert html content to open xml and download a document out of it.
Below is the code that I have,
Could you please let us know if this is supported or not? Or am I missing anything?
Thanks for the wonderful HtmlConverter code. I'm using the version 1.5 in my application to convert html content to open xml and download a document out of it.
Below is the code that I have,
using (var stream = new MemoryStream())
{
// Create a Wordprocessing document.
using (WordprocessingDocument myDoc = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document, true))
{
// Add a new main document part.
// Create DOM tree for simple document.
MainDocumentPart mainPart = myDoc.MainDocumentPart;
if (mainPart == null)
{
mainPart = myDoc.AddMainDocumentPart();
new Document(new Body()).Save(mainPart);
}
HtmlConverter converter = new HtmlConverter(mainPart);
Body body = mainPart.Document.Body;
// Append elements appropriately after converting the html to openxml format.
var paragraphs = converter.Parse(htmlContent);
for (int i = 0; i < paragraphs.Count; i++)
{
body.Append(paragraphs[i]);
}
// Save changes to the main document part.
mainPart.Document.Save();
myDoc.Close();
}
stream.Position = 0;
stream.CopyTo(Response.OutputStream);
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
Response.AddHeader("Content-Disposition", "attachment;filename=" + docName + ".docx");
Response.Flush();
Response.End();
}
Here, htmlContent that I pass into the parse method looks like below<h1 style=\"text-align:left;\">This is heading 1</h1>
<h2 style=\"text-align:left;\">This is heading 2</h2>
<h3>This is heading 3</h3>
<p><span style=\"font-family:Georgia,serif;\">This text is in Georgia font</span></p>
<p><span style=\"font-family:Arial,Helvetica,sans-serif;\">This text is in Arial font</span></p>
<p><span style=\"font-family:'Times New Roman',Times,serif;\">This text is in Times New Roman font</span></p>
But none of the above heading levels or the font name changed texts are getting displayed in the downloaded Open XML document.Could you please let us know if this is supported or not? Or am I missing anything?