本篇内容介绍使用Spire.Doc for .NET在Word中添加Latex数学公式和符号的方法。编辑代码前,将Spire.Doc.dll文件添加引用至VS程序。dll文件包可通过官网下载导入(如果下载的是pack包,需要将Spire.Doc for .NET包解压安装到指定路径,dll文件可在安装路径下的Bin中找到;如果下载的是hotfix包,则无需安装,可直接在文件夹Bin下找到dll);或者通过Nuget搜索下载导入。
注意:需要使用7.6.5版本及以上的Spire.Doc for .NET,本文中下载使用的是hotfix 8.4.2版本
using Spire.Doc; Spire.Doc.Documents; Spire.Doc.Fields.OMath; namespace Create { class Program { static void Main(string[] args) { //新建word实例 Document doc = new Document(); 添加一个section Section section = doc.AddSection(); 添加一个段落 Paragraph paragraph = section.AddParagraph(); 在第一段添加公式 OfficeMath officeMath = OfficeMath(doc); paragraph.Items.Add(officeMath); officeMath.FromLatexMathCode("x^{2}+\\sqrt{x^{2}+1}=2"); 添加第二个公式到第二段 Paragraph paragraph2 = section.AddParagraph(); OfficeMath officeMath1 = OfficeMath(doc); paragraph2.Items.Add(officeMath1); officeMath1.FromLatexMathCode(\\forall x \\in X,\\quad \\exists y \\leq \\epsilon添加符号到第三段 Paragraph paragraph3 = section.AddParagraph(); OfficeMath officeMath2 = OfficeMath(doc); paragraph3.Items.Add(officeMath2); officeMath2.FromLatexMathCode( \\alpha,\\beta,\\gamma,\\Gamma,\\pi,\\Pi,\\phi,\\varphi,\\mu,\\Phi保存文档 doc.SavetoFile(result.docx,FileFormat.Docx); Sy@R_404[email protected](); } } }
(完)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。