C# 插入文本框到PPT幻灯片

在文本框中我们可以实现的操作有很多,如插入文字、图片、设置字体大小、颜色、文本框背景填充、边框设置等。下面的示例中,将介绍通过C# 在PPT幻灯片中插入幻灯片的方法。

示例要点包括:

  • 插入文本到文本框
  • 设置边框颜色、粗细
  • 文本框背景色填充
  • 设置文本框旋转
  • 设置文本框阴影效果

使用工具:Free Spire.Presentation for .NET 3.3(免费版)

注:安装后,注意在程序中添加引用Spire.Presentaton.dll(dll可在安装路径下的Bin文件夹中获取)


 

C# 代码(供参考)

 

using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace InsertTextbox_PPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //实例化Presentation类对象,加载文档并获取第一个幻灯片
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("test.pptx");
            ISlide slide = presentation.Slides[0];

            //添加一个文本框(shape)到第一张幻灯片并添加文字。
            IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(400, 250, 500, 200));
            string textString = "宮崎駿は、1941年1月5日、東京都文京区生まれ。" +
                                "アニメーター、アニメーター、漫画家、アニメーター、アニメーション脚本家。" +
                                " 東京学習研究所大学政治経済学科卒業。" +
                                "1963年には、東営アニメーションカンパニーに入社し、アニメーターとして働いていました。" +
                                "1971年に手塚治虫が制作した「バグプロダクションアニメーション部」に参加。";
            shape.AppendTextFrame(textString);

            //设置shape线条颜色和宽度
            shape.Line.FillType = FillFormatType.Solid;
            shape.Line.Width = 1.5;
            shape.Line.SolidFillColor.Color = Color.LightYellow;

            //设置shape填充颜色为渐变色
            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Gradient;
            shape.Fill.Gradient.GradientShape = Spire.Presentation.Drawing.GradientShapeType.Linear;
            shape.Fill.Gradient.GradientStops.Append(1f, KnownColors.SkyBlue);
            shape.Fill.Gradient.GradientStops.Append(0, KnownColors.LightPink);

            //设置shape阴影
            Spire.Presentation.Drawing.OuterShadowEffect shadow = new Spire.Presentation.Drawing.OuterShadowEffect();
            shadow.BlurRadius = 20;
            shadow.Direction = 30;
            shadow.Distance = 8;
            shadow.ColorFormat.Color = Color.LightGray;
            shape.EffectDag.OuterShadowEffect = shadow;

            //设置shape向左旋转10度,(向右旋转为正) 
            shape.Rotation = -10;

            //保存并打开文档
            presentation.SaveToFile("result.pptx", FileFormat.Pptx2007);
            System.Diagnostics.Process.Start("result.pptx");
        }
    }
}

 

文本框添加效果前后对比:

 

添加前:



 

文本框添加效果:



 

 

 

(本文完)

 

猜你喜欢

转载自miaonly.iteye.com/blog/2432275