C# 在PPT中添加Latex数学公式

2025-11-06 08:21:02

1、在VS中添加引用dll文件(需要将库手动下载至本地,然后解压,dll在Bin文件夹下):

C# 在PPT中添加Latex数学公式

C# 在PPT中添加Latex数学公式

C# 在PPT中添加Latex数学公式

C# 在PPT中添加Latex数学公式

2、完成添加引用效果:

C# 在PPT中添加Latex数学公式

1、using Spire.Presentation;

using Spire.Presentation.Drawing;

using System.Drawing;

namespace AddFormular

{

    class Program

    {

        static void Main(string[] args)

        {

            //新建一个PPT幻灯片文档,并获取第一张幻灯片(新建的PPT文档已默认包含一张幻灯片)

            Presentation ppt = new Presentation();

            ISlide slide = ppt.Slides[0];

            //添加形状到幻灯片

            IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(30, 100, 400, 30));

            shape.Fill.FillType = FillFormatType.None;

            shape.ShapeStyle.LineColor.Color = Color.White;

            shape.TextFrame.Paragraphs.Clear();

            //添加公式

            string latexMathCode = @"$ f(x,y) = \sqrt[n]{{x^2}{y^3}} $";

            shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexMathCode);           

            //保存

            ppt.SaveToFile("AddLatexMathCode.pptx", FileFormat.Pptx2013);

        }

    }

}

2、执行程序代码,生成PPT文档,按照代码中的文件路径,可在VS程序项目文件夹下查看,如图效果:

C# 在PPT中添加Latex数学公式

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢