该文将详细介绍如何使用spire.doc for java添加latex 数学公式和 mathmlcode到word 文档。
import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.omath.*;
public class test {
public static void main(string[] args){
//新建word示例,添加一个section
document doc = new document();
section section = doc.addsection();
//添加段落
paragraph paragraph = section.addparagraph();
//插入latex 数学公式
officemath officemath = new officemath(doc);
paragraph.getitems().add(officemath);
officemath.fromlatexmathcode("x^{2} \\sqrt{{x^{2} 1}} 1");
//添加段落二
paragraph paragraph2 = section.addparagraph();
//插入mathmlcode数学公式
officemath officemath2 = new officemath(doc);
paragraph2.getitems().add(officemath2);
officemath2.frommathmlcode("x 2 x 2 1 1 ");
//保存文档
string result = "output/addmathequation.docx";
doc.savetofile(result, fileformat.docx_2013);
}
}
效果图: