脚本宝典收集整理的这篇文章主要介绍了C# 在PPT中添加数学公式,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
本次内容介绍在C#程序中给PPT幻灯片添加Latex数学公式,添加公式前,首先需要在幻灯片中插入一个Shape形状,在形状的段落中通过方法 Paragraphs.AddParagraphFromLatexMathCode( string latexMathCode)写入公式,最后保存。
本次使用PPT库 Spire.Presentation for .NET Version 6.9.2,在VS程序中添加引用Spire.Presentation.dll。2种引用方法:
using Spire.Presentation; using Spire.Presentation.Drawing; using System.Drawing; namespace AddFormula { class Program { static void Main(string[] args) { //新建一个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); System.Diagnostics.Process.Start("AddLatexMathCode.pptx"); } } }
Imports Spire.Presentation Imports Spire.Presentation.Drawing Imports System.Drawing Namespace AddFormula Class Program Private Shared Sub Main(args As String()) '新建一个PPT幻灯片文档,并获取第一张幻灯片(新建的幻灯片已默认包含一张幻灯片) Dim ppt As New Presentation() Dim slide As ISlide = ppt.Slides(0) '添加形状到幻灯片 Dim shape As IAutoShape = 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() '添加公式 Dim latexMathCode As String = "$ f(x,y) = sqrt[n]{{x^2}{y^3}} $" shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexMathCode) '保存 ppt.SaveToFile("AddLatexMathCode.pptx", FileFormat.Pptx2013) System.Diagnostics.Process.Start("AddLatexMathCode.pptx") End Sub End Class End Namespace
—End—
以上是脚本宝典为你收集整理的C# 在PPT中添加数学公式全部内容,希望文章能够帮你解决C# 在PPT中添加数学公式所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。