Các tính năng và khả năng
Các tính năng và khả năng
Aspose.Slides FOSS for .NET provides a broad set of capabilities for working with PowerPoint .pptx tập tin một cách lập trình. Trang này liệt kê tất cả các khu vực tính năng được hỗ trợ cùng với các ví dụ mã đại diện.
Nhập/Xuất Bản trình chiếu
Mở một tệp hiện có .pptx tập tin hoặc tạo một tệp mới, sau đó lưu lại dưới định dạng 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);
}Lưu ý: PPTX là định dạng lưu duy nhất được hỗ trợ. Xuất ra PDF, HTML, SVG, hoặc hình ảnh không khả dụng.
Các phần XML không xác định trong tệp nguồn được giữ nguyên khi lưu, vì vậy việc mở và lưu lại một .pptx sẽ không bao giờ loại bỏ nội dung mà thư viện chưa hiểu.
Quản lý Slide
Thêm, xóa, sao chép và sắp xếp lại các slide.
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);Hình dạng
Thêm AutoShapes, PictureFrames, Tables và Connectors vào một slide.
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);Tables
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);Connectors
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);Định dạng Văn bản
Định dạng văn bản ở mức đoạn và ký tự bằng cách sử dụng 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 đặt thuộc tính một cách rõ ràng; NullableBool.NotDefined kế thừa từ mẫu slide.
Các loại tô
Áp dụng tô màu đặc, gradient, họa tiết hoặc hình ảnh cho các hình dạng.
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);Hiệu ứng trực quan
Áp dụng bóng ngoài, phát sáng, viền mềm, làm mờ, phản chiếu và bóng trong cho các hình dạng.
Các thuộc tính hiệu ứng có thể truy cập thông qua shape.EffectFormat. Gọi EnableOuterShadowEffect(), EnableGlowEffect(), EnableSoftEdgeEffect(), SetBlurEffect(), EnableReflectionEffect(), hoặc EnableInnerShadowEffect() để cấu hình từng cái một cách độc lập.
3D Formatting
Áp dụng viền 3D, camera, bộ đèn, vật liệu và độ sâu đùn qua shape.ThreeDFormat. Điều này kiểm soát độ sâu hình ảnh và mô hình chiếu sáng cho việc hiển thị hình dạng trong các trình xem PPTX hỗ trợ hiệu ứng 3D.
Ghi chú người thuyết trình
Đính kèm ghi chú vào bất kỳ slide nào bằng cách 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);Bình luận
Thêm bình luận dạng chuỗi với thông tin tác giả và vị trí slide.
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);Hình ảnh nhúng
Nhúng một hình ảnh từ tệp vào bản trình chiếu và thêm nó vào slide dưới dạng một 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);Thuộc tính tài liệu
Đọc và ghi các thuộc tính tài liệu core, app và tùy chỉnh.
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);Các hạn chế đã biết
Các khu vực sau gây ra NotImplementedException và không có sẵn trong phiên bản này:
| Khu vực | Trạng thái |
|---|---|
| Biểu đồ | Chưa triển khai |
| SmartArt | Chưa triển khai |
| Hoạt ảnh và chuyển đổi | Chưa triển khai |
| Xuất PDF / HTML / SVG / hình ảnh | Chưa triển khai (chỉ PPTX) |
| Macro VBA | Chưa triển khai |
| Chữ ký số | Chưa triển khai |
| Siêu liên kết và cài đặt hành động | Chưa triển khai |
| Đối tượng OLE | Chưa được triển khai |
| Văn bản toán học | Chưa được triển khai |
Xem Thêm
- Bắt đầu: Cài đặt và chương trình đầu tiên
- Tham chiếu API: Tham chiếu lớp và phương thức
- Hướng dẫn cách làm: Bài viết hướng tới nhiệm vụ