none
How to read Math Equations from Powerpoint and write it to Word document in C# RRS feed

  • Question

  • I am developing a PowerPoint extraction tool since march 2014 which extracts the words or paragraphs from PowerPoint and write it to word document. It has been developed. During the testing. we found that Math Equation has not being fetched from PowerPoint slide.
    I am using Microsoft.Office.Interop.Powerpoint.dll library. i am reading file such as given below.

    var powerPoint = new Application {WindowState=PpWindowState.ppWindowMinimized};

    var oPresSet = powerPoint.Presentations;     

    Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(pptName, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);     

    var str = oPres.Slides[1].NotesPage.Shapes[2].TextFrame.TextRange.Text;

    Here is screenshot of input of PPT.

    Image: http://s4.postimg.org/ryi2tls3x/input.png

    but i want to read math equation which have in the PowerPoint slide.
    i tried to use these MathZones and get_MathZones but i didn't get much about it that how to use MathZones proerety. On other hand, get_MathZones method gives the same garbled text. i used the get_MathZones method such as given below.

     var strObj = oPres.Slides[1].NotesPage.Shapes[2].TextFrame2.TextRange.MathZones.get_MathZones();

     var str = strObj.Text;

    Here is screenshot of output of ppt as garbled text.

    Image: http://s24.postimg.org/pxqgct89h/ouput.png

    I just want to read Math Equation from PowerPoint then want to write it in word document programatically. Here firstly i am not able to read Math Equation. Suggest me any solutions.


    Friday, February 6, 2015 11:29 AM

Answers

  • Hi Suresh,

    The easest solution I can think of is to copy the math equation from the PowerPoint then paste in the Word document directly, there's actually no way to convert it to plain text, some equation is very complext, String variable is not suitable in this case. For example, this code works fine:

    var powerPoint = new Application { WindowState = PpWindowState.ppWindowMinimized };
                var oPresSet = powerPoint.Presentations;
                Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(@"C:\test.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
    
                var strObj = oPres.Slides[1].NotesPage.Shapes[2].TextFrame2.TextRange.MathZones.get_MathZones();
                strObj.Copy();
    
                Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
                wordApp.Visible = true;
                Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Add();
                doc.Range(0, 0).Paste(); 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, February 9, 2015 5:41 AM
    Moderator

All replies

  • Hi Suresh,

    The easest solution I can think of is to copy the math equation from the PowerPoint then paste in the Word document directly, there's actually no way to convert it to plain text, some equation is very complext, String variable is not suitable in this case. For example, this code works fine:

    var powerPoint = new Application { WindowState = PpWindowState.ppWindowMinimized };
                var oPresSet = powerPoint.Presentations;
                Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(@"C:\test.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
    
                var strObj = oPres.Slides[1].NotesPage.Shapes[2].TextFrame2.TextRange.MathZones.get_MathZones();
                strObj.Copy();
    
                Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
                wordApp.Visible = true;
                Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Add();
                doc.Range(0, 0).Paste(); 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, February 9, 2015 5:41 AM
    Moderator
  • Hi Caillen Zhong,

    Your answer is helping me. But there is another problem that I just want to copy and paste a particular part of the textrange.



    Monday, February 9, 2015 6:54 AM