Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Feb 25, 2022 8:52 am

public DocOleObject appendOleObject(byte[] oleBytes, DocPicture olePicture, OleObjectType type) API how to use?
OleObjectType.Math_Type
I want to pass spire.Doc.5.2.3.jar inserts a mathematical equation into word in the Java environment,
and the mathematical equation can be edited by opening MathType through ole.
However, the API doesn't know how to use it.

yangzhenbiao
 
Posts: 2
Joined: Fri Feb 25, 2022 8:43 am

Fri Feb 25, 2022 9:16 am

Hello,

Thanks for your inquiry!

Please refer to the following article to insert math equations to the Word file : Java insert math equation to Word

If you want to get or edit the math equation which already exists, please refer to the following code to achieve this:
Code: Select all
        Document doc = new Document();
        doc.loadFromFile("data/GetMathEquation.docx");
        StringBuilder stringBuilder = new StringBuilder();
        for(int i=0;i<doc.getSections().getCount();i++){
            for(int j=0;j<doc.getSections().get(i).getParagraphs().getCount();j++){
                for(int k=0;k<doc.getSections().get(i).getParagraphs().get(j).getChildObjects().getCount();k++){
                    DocumentObject obj =doc.getSections().get(i).getParagraphs().get(j).getChildObjects().get(k);
                    if (obj instanceof OfficeMath) {
                        OfficeMath math=(OfficeMath)doc.getSections().get(i).getParagraphs().get(j).getChildObjects().get(k);
                        //get or edit as you wish
                        stringBuilder.append(math.toMathMLCode()+"\n");
                    }
                }
            }
        }


If you have any other questions, just feel free to contact us.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Sun Feb 27, 2022 2:58 am

Thank you for your answer. The math equations of docx file can be modified manually through MathType, but it seems impossible.

yangzhenbiao
 
Posts: 2
Joined: Fri Feb 25, 2022 8:43 am

Mon Feb 28, 2022 2:55 am

Hello,

Thanks for your feedback!

You can refer to the following code to change the math equations:
Code: Select all
      String codeString = "<mml:math xmlns:mml=\"http://www.w3.org/1998/Math/MathML\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\"><mml:mn>2</mml:mn><mml:mi>α</mml:mi><mml:mo>-</mml:mo><mml:mi>s</mml:mi><mml:mi>i</mml:mi><mml:mi>n</mml:mi><mml:mi>y</mml:mi><mml:mo>+</mml:mo><mml:mi>x</mml:mi></mml:math>";

......
                  OfficeMath math = (OfficeMath) doc.getSections().get(i).getParagraphs().get(j).getChildObjects()
                        .get(k);
                  math.getChildObjects().clear();
                  math.fromMathMLCode(codeString);
......


If you have any other questions, just feel free to contact us.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Mon Mar 07, 2022 8:33 am

Hello,

Hope you are doing well!

Has the issue been solved now? Could you please give us some feedback at your convenience?

Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.Doc