1

I want to create a document (*.docx) using docx library. I have HTML formatted text from a rich text editor, and I want to save it as it is. I am not able to find any place where I can get the help. My current code is very basic, and is copy paste from there help.

My code looks like:

private string CreateDocumentFromText()
{
    string filePath= Server.MapPath("../DocXExample.docx");
    var document = Novacode.DocX.Create(filePath);
    document.InsertParagraph("<b>Test</b>");            
    document.Save();
    return fileName;
}

Document has content as:

 <b>Test</b>

Whereas I want it to be:

Test

DLeh
  • 23,806
  • 16
  • 84
  • 128
PM.
  • 1,735
  • 1
  • 30
  • 38

1 Answers1

1

You have to convert it to xml element. Try DocumentFormat.OpenXml library

Jan
  • 26
  • 3
  • Can you point to some example, because when I looked for it, I found that I will have to insert it as external content, but then user experience will not be same as inserting the text in word format. Any idea? – PM. Jan 08 '15 at 05:39
  • 1
    I found the solution in another thread [Here](http://stackoverflow.com/questions/18089921/add-html-string-to-openxml-docx-document) – PM. Jan 08 '15 at 07:20