使用 VSTO 和 Aspose.Slides for .NET 建立新簡報

Creating a Presentation

以下兩個程式碼範例說明如何使用 VSTO 與 Aspose.Slides for .NET 來達成相同的目標。第一個範例是 VSTO第二個範例 使用 Aspose.Slides。

VSTO Example

The VSTO output

todo:image_alt_text

//注意:PowerPoint 是在上方這樣定義的命名空間
//using PowerPoint = Microsoft.Office.Interop.PowerPoint;

//建立簡報
PowerPoint.Presentation pres = Globals.ThisAddIn.Application
	.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse);

//取得標題投影片版面配置
PowerPoint.CustomLayout layout = pres.SlideMaster.
	CustomLayouts[PowerPoint.PpSlideLayout.ppLayoutTitle];

//新增標題投影片。
PowerPoint.Slide slide = pres.Slides.AddSlide(1, layout);

//設定標題文字
slide.Shapes.Title.TextFrame.TextRange.Text = "Slide Title Heading";

//設定副標題文字
slide.Shapes[2].TextFrame.TextRange.Text = "Slide Title Sub-Heading";

//將輸出寫入磁碟
pres.SaveAs("c:\\outVSTO.ppt",
	PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,
	Microsoft.Office.Core.MsoTriState.msoFalse);

Aspose.Slides for .NET Example

The output from Aspose.Slides

todo:image_alt_text

//建立簡報
Presentation pres = new Presentation();

//新增標題投影片
ISlide slide = pres.Slides.AddEmptySlide(pres.LayoutSlides[0]);


//設定標題文字
((IAutoShape)slide.Shapes[0]).TextFrame.Text = "Slide Title Heading";

//設定副標題文字
((IAutoShape)slide.Shapes[1]).TextFrame.Text = "Slide Title Sub-Heading";

//將輸出寫入磁碟
pres.Save("c:\\data\\outAsposeSlides.pptx", SaveFormat.Ppt);