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