功能与能力
功能与能力
Aspose.Slides FOSS for .NET provides a broad set of capabilities for working with PowerPoint .pptx 以编程方式处理文件。本页列出所有受支持的功能区域,并提供相应的代码示例。.
演示文稿 I/O
打开现有的 .pptx 文件或创建一个新文件,然后保存回 PPTX 格式。.
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
// Open an existing presentation
using (var prs = new Presentation("input.pptx"))
{
Console.WriteLine($"Slide count: {prs.Slides.Count}");
prs.Save("output.pptx", SaveFormat.Pptx);
}
// Create a new presentation (starts with one blank slide)
using (var prs = new Presentation())
{
prs.Save("new.pptx", SaveFormat.Pptx);
}注意:: PPTX 是唯一受支持的保存格式。导出为 PDF、HTML、SVG 或图像的功能不可用。.
源文件中的未知 XML 部分在保存时会原样保留,因此打开并重新保存一个 .pptx 永远不会剥离库尚未理解的内容。.
幻灯片管理
添加、删除、克隆和重新排序幻灯片。.
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
// Access the first slide
var slide = prs.Slides[0];
// Add an additional blank slide at the end
prs.Slides.AddEmptySlide(prs.LayoutSlides[0]);
Console.WriteLine($"Total slides: {prs.Slides.Count}");
prs.Save("multi-slide.pptx", SaveFormat.Pptx);形状
向幻灯片添加 AutoShapes、PictureFrames、表格和连接线。.
AutoShapes
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var slide = prs.Slides[0];
// Add a rectangle at (x=50, y=50) with width=300, height=100
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 300, 100);
shape.AddTextFrame("Aspose.Slides FOSS");
prs.Save("shapes.pptx", SaveFormat.Pptx);表格
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var slide = prs.Slides[0];
// Column widths and row heights in points
double[] colWidths = { 120.0, 120.0, 120.0 };
double[] rowHeights = { 40.0, 40.0, 40.0 };
var table = slide.Shapes.AddTable(50, 50, colWidths, rowHeights);
table.Rows[0][0].TextFrame.Text = "Product";
table.Rows[0][1].TextFrame.Text = "Quantity";
table.Rows[0][2].TextFrame.Text = "Price";
prs.Save("table.pptx", SaveFormat.Pptx);连接线
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var slide = prs.Slides[0];
var box1 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 100, 150, 60);
var box2 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 350, 100, 150, 60);
var conn = slide.Shapes.AddConnector(ShapeType.BentConnector3, 0, 0, 10, 10);
conn.StartShapeConnectedTo = box1;
conn.StartShapeConnectionSiteIndex = 3; // right side
conn.EndShapeConnectedTo = box2;
conn.EndShapeConnectionSiteIndex = 1; // left side
prs.Save("connector.pptx", SaveFormat.Pptx);文本格式化
使用 在段落和字符层面格式化文本 PortionFormat.
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Drawing;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var slide = prs.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 500, 150);
var tf = shape.AddTextFrame("Bold blue heading");
var fmt = tf.Paragraphs[0].Portions[0].PortionFormat;
fmt.FontHeight = 28;
fmt.FontBold = NullableBool.True;
fmt.FillFormat.FillType = FillType.Solid;
fmt.FillFormat.SolidFillColor.Color = Color.FromArgb(255, 0, 70, 127);
prs.Save("text.pptx", SaveFormat.Pptx);NullableBool.True 显式设置属性;; NullableBool.NotDefined 继承自幻灯片母版。.
填充类型
对形状应用纯色、渐变、图案或图片填充。.
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Drawing;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var slide = prs.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 300, 150);
// Solid fill
shape.FillFormat.FillType = FillType.Solid;
shape.FillFormat.SolidFillColor.Color = Color.FromArgb(255, 30, 120, 200);
prs.Save("fill.pptx", SaveFormat.Pptx);视觉效果
对形状应用外阴影、发光、柔边、模糊、反射和内阴影。.
效果属性可通过 访问 shape.EffectFormat.。调用 EnableOuterShadowEffect(), EnableGlowEffect(), EnableSoftEdgeEffect(), SetBlurEffect(), EnableReflectionEffect(),,或 EnableInnerShadowEffect() 以独立配置每个。.
3D Formatting
通过 应用 3D 倾斜、摄像机、灯光装置、材质和挤出深度 shape.ThreeDFormat.。这控制了在支持 3D 效果的 PPTX 查看器中形状渲染的视觉深度和光照模型。.
演讲者备注
使用以下方式将备注附加到任意幻灯片 NotesSlideManager.
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var notes = prs.Slides[0].NotesSlideManager.AddNotesSlide();
notes.NotesTextFrame.Text = "Key talking point: emphasize the ROI benefit.";
prs.Save("notes.pptx", SaveFormat.Pptx);评论
添加带有作者信息和幻灯片位置的线程式评论。.
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Drawing;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var author = prs.CommentAuthors.AddAuthor("Jane Smith", "JS");
var slide = prs.Slides[0];
author.Comments.AddComment(
"Please verify this data before the presentation.",
slide,
new PointF(2.0f, 2.0f),
DateTime.Now
);
prs.Save("comments.pptx", SaveFormat.Pptx);嵌入图像
将文件中的图像嵌入演示文稿,并将其作为 PictureFrame.
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var imageData = File.ReadAllBytes("logo.png");
var image = prs.Images.AddImage(imageData);
var slide = prs.Slides[0];
slide.Shapes.AddPictureFrame(ShapeType.Rectangle, 50, 50, 200, 150, image);
prs.Save("with-image.pptx", SaveFormat.Pptx);文档属性
读取和写入核心、应用和自定义文档属性。.
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var props = prs.DocumentProperties;
// Core properties
props.Title = "Q1 Results";
props.Author = "Finance Team";
props.Subject = "Quarterly Review";
props.Keywords = "Q1, finance, results";
// Custom property
props.SetCustomPropertyValue("ReviewedBy", "Legal Team");
prs.Save("deck.pptx", SaveFormat.Pptx);已知限制
以下区域引发 NotImplementedException 且在此版本中不可用::
| 区域 | 状态 |
|---|---|
| 图表 | 未实现 |
| SmartArt | 未实现 |
| 动画和过渡 | 未实现 |
| PDF / HTML / SVG / 图像导出 | 未实现(仅 PPTX) |
| VBA 宏 | 未实现 |
| 数字签名 | 未实现 |
| 超链接和操作设置 | 未实现 |
| OLE 对象 | 未实现 |
| 数学文本 | 未实现 |