Spire.Doc系列教程(9):创建 PowerPoint 文档

创建简单的PowerPoint文档

//新建一个PowerPoint文档(默认包含一页空白幻灯片)Presentation ppt = new Presentation();//设置幻灯片大小和方向ppt.SlideSize.Type = SlideSizeType.Screen16x9;ppt.SlideSize.Orientation = SlideOrienation.Landscape;//为幻灯片设置背景图片string ImageFile = "background.jpg";RectangleF rect = new RectangleF(0, 0, ppt.SlideSize.Size.Width, ppt.SlideSize.Size.Height);ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture;IEmbedImage image = ppt.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image as IImageData;//添加一个图形(shape)到第一张幻灯片IAutoShape textboxShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 600, 100));textboxShape.ShapeStyle.LineColor.Color = Color.Transparent;textboxShape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;//清除图形上的段落(默认有一个空白段落)textboxShape.TextFrame.Paragraphs.Clear();//在图形上添加段落及内容textboxShape.TextFrame.Paragraphs.Append(new TextParagraph());textboxShape.TextFrame.Paragraphs[0].TextRanges.Append(new TextRange("Spire.Presentation for .NET"));textboxShape.TextFrame.Paragraphs[0].SpaceAfter = 50f;//添加第二段及内容textboxShape.TextFrame.Paragraphs.Append(new TextParagraph());string text = "一款专业的 PowerPoint 组件,使用该组件,开发者可以在 .NET 平台上对 PowerPoint 文档进行生成、读取、写入、修改、"             + "转换和打印等操作。 作为一个独立的控件,Spire.Presentation for .NET 的运行无需要安装 Microsoft PowerPoint。";textboxShape.TextFrame.Paragraphs[1].TextRanges.Append(new TextRange(text));//设置段落中文字的字体、大小、颜色及段落的对齐方式、段首缩进距离foreach (TextParagraph para in textboxShape.TextFrame.Paragraphs){    para.TextRanges[0].LatinFont = new TextFont("Arial Rounded MT Bold");    para.TextRanges[0].FontHeight = 13f;    para.TextRanges[0].Fill.FillType = FillFormatType.Solid;    para.TextRanges[0].Fill.SolidColor.Color = Color.Black;    para.Alignment = TextAlignmentType.Left;    para.Indent = 35;}//保存文档ppt.SaveToFile("创建PowerPoint.pptx", FileFormat.Pptx2013)

Spire.Doc

设置文档属性

//新建一个文档Presentation ppt= new Presentation();//通过DocumentProperty设置文档属性ppt.DocumentProperty.Application = "Spire.Presentation";ppt.DocumentProperty.Author = "http://www.e-iceblue.com/";ppt.DocumentProperty.Company = "冰蓝科技有限公司";ppt.DocumentProperty.Keywords = "C#,PowerPoint文档属性";ppt.DocumentProperty.Comments = "无";ppt.DocumentProperty.Category = "PowerPoint教程";ppt.DocumentProperty.Title = "如何为PowerPoint文档添加属性";ppt.DocumentProperty.Subject = "Add document properties in C#";ppt.DocumentProperty.Manager = "Gary";//保存文档ppt.SaveToFile("设置文档属性.pptx", FileFormat.Pptx2013);

Spire.Doc
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2018年9月6日
下一篇 2018年9月6日

相关推荐

发表回复

登录后才能评论