文档彩票走势图>>Spire.Doc系列教程>>Spire.Doc功能演示:在Java中以编程方式将数学方程式插入Word
Spire.Doc功能演示:在Java中以编程方式将数学方程式插入Word
Spire.Doc for Java 是一款专业的Java Word组件,开发人员使用它可以轻松地将Word文档创建、读取、编辑、转换和打印等功能集成到自己的Java应用程序中。
本文将演示如何在Java应用程序中使用Spire.Doc for Java到Latex Math方程和MathMLCode到Word文档。可点击此处下载最新版测试。
import com.spire.doc.*; import com.spire.doc.documents.*; import com.spire.doc.fields.omath.*; public class wordEquation { public static void main(String[] args){ //Create a new instance of Word and add a section Document doc = new Document(); Section section = doc.addSection(); //Add a paragraph Paragraph paragraph = section.addParagraph(); //Add Latex Math code OfficeMath officeMath = new OfficeMath(doc); paragraph.getItems().add(officeMath); officeMath.fromLatexMathCode("x^{2}+\\sqrt{{x^{2}+1}}+1"); //Add another paragraph Paragraph paragraph2 = section.addParagraph(); //Add MathMLCode OfficeMath officeMath2 = new OfficeMath(doc); paragraph2.getItems().add(officeMath2); officeMath2.fromMathMLCode("x2+x2+1+1"); //Save the document to file String result = "output/addMathEquation.docx"; doc.saveToFile(result, FileFormat.Docx_2013); } }
输出结果