加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C# 在Word中添加Latex 数学公式和符号

发布时间:2020-12-16 01:06:08 所属栏目:百科 来源:网络整理
导读:本篇内容介绍使用Spire.Doc for .NET在Word中添加Latex数学公式和符号的方法。编辑代码前,将Spire.Doc.dll文件添加引用至VS程序。dll文件包可通过 官网下载导入 (如果下载的是pack包,需要将Spire.Doc for .NET包解压安装到指定路径,dll文件可在安装路径

本篇内容介绍使用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版本

dll添加引用效果,如下图:

?

?

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);
            System.Diagnostics.Process.Start();
        }
    }
}

公式/符号添加效果:

?

(完)

?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读