从spire.doc 版本7.6.5开始,spire.doc支持添加latex数学公式和符号到word文档。 该文将详细介绍如何使用c#添加latex 数学公式和符号到word 文档。
c#
//创建文档
document doc = new document();
//添加section
section section = doc.addsection();
//添加段落
paragraph paragraph = section.addparagraph();
//添加公式
officemath officemath = new officemath(doc);
paragraph.items.add(officemath);
officemath.fromlatexmathcode("x^{2} \\sqrt{x^{2} 1}=2");
paragraph paragraph2 = section.addparagraph();
officemath officemath1 = new officemath(doc);
paragraph2.items.add(officemath1);
officemath1.fromlatexmathcode("\\forall x \\in x, \\quad \\exists y \\leq \\epsilon");
//添加符号
paragraph paragraph3 = section.addparagraph();
officemath officemath2 = new officemath(doc);
paragraph3.items.add(officemath2);
officemath2.fromlatexmathcode(" \\alpha,\\beta, \\gamma, \\gamma, \\pi, \\pi, \\phi, \\varphi, \\mu, \\phi");
//保存文档
doc.savetofile("equation.docx", fileformat.docx);
system.diagnostics.process.start("equation.docx");
vb.net
dim doc as document = new document
dim section as section = doc.addsection
dim paragraph as paragraph = section.addparagraph
dim officemath as officemath = new officemath(doc)
paragraph.items.add(officemath)
officemath.fromlatexmathcode("x^{2} \sqrt{x^{2} 1}=2")
dim paragraph2 as paragraph = section.addparagraph
dim officemath1 as officemath = new officemath(doc)
paragraph2.items.add(officemath1)
officemath1.fromlatexmathcode("\forall x \in x, \quad \exists y \leq \epsilon")
dim paragraph3 as paragraph = section.addparagraph
dim officemath2 as officemath = new officemath(doc)
paragraph3.items.add(officemath2)
officemath2.fromlatexmathcode(" \alpha,\beta, \gamma, \gamma, \pi, \pi, \phi, \varphi, \mu, \phi")
doc.savetofile("equation.docx", fileformat.docx)
system.diagnostics.process.start("equation.docx")
效果图: