-3

I have one word file in which 2-3 mathematical equations written. I am succeed in retrieve it, but any how i am not able to bind it same as written in word file in WPF with C#. Thanks in advance.

private XpsDocument ConvertWordDocToXPSDoc(string wordDocName, string xpsDocName)
     {
         // Create a WordApplication and add Document to it
         Microsoft.Office.Interop.Word.Application
             wordApplication = new Microsoft.Office.Interop.Word.Application();
         wordApplication.Documents.Add(wordDocName);


         Document doc = wordApplication.ActiveDocument;
         // You must ensure you have Microsoft.Office.Interop.Word.Dll version 12.
         // Version 11 or previous versions do not have WdSaveFormat.wdFormatXPS option
         try
         {
             //doc.SaveAs(xpsDocName, WdSaveFormat.wdFormatXPS);
             wordApplication.Quit();
             string strRetval = "";
             System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
             Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
             object miss = System.Reflection.Missing.Value;
             object path = wordDocName;//@"C:\DOC\myDocument.docx";
             object readOnly = true;
             Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
             List<string> lines = new List<string>();
             string totaltext = "";
             for (int i = 0; i < docs.Paragraphs.Count; i++)
             {
                 if (!string.IsNullOrEmpty(docs.Paragraphs[i + 1].Range.Text.ToString().Replace("\r", string.Empty)))
                 {
                     totaltext = " \r\n " + docs.Paragraphs[i + 1].Range.Text.ToString();
                     lines.Add(totaltext);

                 }
             }
             //In totaltext i will get text as well as mathematical expression. Text showing correctly but mathematical equation lost format wile binding it to textblock.
             txtFileBlock.Text = totaltext;

             XpsDocument xpsDoc = new XpsDocument(xpsDocName, System.IO.FileAccess.Read);
             return xpsDoc;
         }
         catch (Exception exp)
         {
             string str = exp.Message;
         }
         return null;
     }

Following is my equation in doc file. enter image description here

But it comes like as follow: enter image description here

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Aditya
  • 44
  • 1
  • 12

1 Answers1

0

I do not think anybody is able to give you universal recipe how to do it.

Please view the following topics that may will give you a way to go:

Converting math equations to C#

Storing math equations from .doc MS Word file & restoring them

Community
  • 1
  • 1
keymusicman
  • 1,281
  • 1
  • 10
  • 20