用C#在WPF中显示格式的数学方程

时间:2015-07-22 10:28:14

标签: c# asp.net wpf data-binding ms-word

我有一个单词文件,其中写入了2-3个数学方程式。我成功检索它,但是我无法将它绑定到与使用C#在WPF中的word文件中编写的相同。 提前谢谢。

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;
     }

以下是我在doc文件中的等式。 enter image description here

但它如下: enter image description here

1 个答案:

答案 0 :(得分:0)

我认为没有人能够为您提供通用配方如何做到这一点。

请查看以下可能为您提供的方法:

Converting math equations to C#

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