2012-03-11 17 views
1

私はテキストを取得するためのHtmlEditorを持っています。 (HTMLをWordに挿入するには?

段落1。

BLOCKQUOTEで段落。

段落2。

私は言葉にHTMLを挿入します。私はopen xmlを使用しますが、仕事はしません。

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

このlinkLinkは非常に便利な

+0

ここでも興味深い回答があります。htt p://stackoverflow.com/questions/187448/insert-html-into-openxml-word-document-net –

答えて

関連する問題