文档彩票走势图>>Spire.Doc系列教程>>Spire.Doc系列教程(9):创建 PowerPoint 文档
Spire.Doc系列教程(9):创建 PowerPoint 文档
PowerPoint文档(幻灯片)是一种常见的演示文档,在演讲,教学,产品演示等方面得到广泛的应用。本文将介绍如何通过编程的方式创建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)
设置文档属性
//新建一个文档 Presentation ppt= new Presentation(); //通过DocumentProperty设置文档属性 ppt.DocumentProperty.Application = "Spire.Presentation"; ppt.DocumentProperty.Author = "//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);