Is it possible to retrieve HTML code from a word document paragraph using OpenXML or Microsoft.Interop? C#

Viewed 45

There exists a way to get HTML code from a paragraph using clipboard. If you select a fragment of a document and copy it, you are able to get HTML data using C#.

var foo = Clipboard.GetData(DataFormats.Html);

Unfortunately it does not meet my criteria. The perfect solution would be to open Word Document using OpenXML library, iterate through paragraphs and create HTML code for each of them.

using (WordprocessingDocument wordDocument = WordprocessingDocument.Open(filePath, true))
{
  var wordDocumentBody = wordDocument.MainDocumentPart.Document.Body;
  foreach(var paragraph in wordDocumentBody.Descendants<Paragraph>())
  {
    if(paragraph.MeetsCriteria()) //Imaginary function that checks if paragraph has important information
      //Ideal scenario
      var paragraphHTML = paragraph.GenerateHTML();
  }
}

I am not interested in converting whole word document into HTML since it would be impossible to differentiate the paragraphs that I am interested in from the others.

If you have any ideas how to generate HTML for single paragraphs using mentioned libraries please let me know below.

0 Answers
Related