1

I have a HtmlEditor for get text . (

Paragraph one.

Paragraph in a blockquote.

Paragraph two.

)

I want insert html to word . I use open xml but dont work .

void ConvertHTML(string htmlFileName, string docFileName)
{
    // Create a Wordprocessing document. 
    using (WordprocessingDocument package = WordprocessingDocument.Create(docFileName, WordprocessingDocumentType.Document))
    {
        // Add a new main document part. 
        package.AddMainDocumentPart();

        // Create the Document DOM. 
        package.MainDocumentPart.Document = new DocumentFormat.OpenXml.Wordprocessing.Document(new Body());
        Body body = package.MainDocumentPart.Document.Body;

        XPathDocument htmlDoc = new XPathDocument(htmlFileName);

        XPathNavigator navigator = htmlDoc.CreateNavigator();
        XmlNamespaceManager mngr = new XmlNamespaceManager(navigator.NameTable);
        mngr.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");

        XPathNodeIterator ni = navigator.Select("html");
        while (ni.MoveNext())
        {
            body.AppendChild<Paragraph>(new Paragraph(new Run(new  Text(ni.Current.Value))));
        }

        // Save changes to the main document part. 
        package.MainDocumentPart.Document.Save();
    }
}

EDIT

This link ,Link is very useful

ar.gorgin
  • 4,765
  • 12
  • 61
  • 100
  • Some interesting answers here as well: http://stackoverflow.com/questions/187448/insert-html-into-openxml-word-document-net – Johann Blais Feb 01 '13 at 06:24

0 Answers0