在 VSTO 和 Aspose.Slides 中建立新簡報
Contents
[
Hide
]
以下展示了兩個程式碼範例,說明如何使用 VSTO 和 Aspose.Slides for .NET 來達成相同的目標。
VSTO
private void CreatePresentation()
{
PowerPoint.Presentation pres = Globals.ThisAddIn.Application
.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse);
//Get the title slide layout
PowerPoint.CustomLayout layout = pres.SlideMaster.
CustomLayouts[PowerPoint.PpSlideLayout.ppLayoutTitle];
//Add a title slide.
PowerPoint.Slide slide=pres.Slides.AddSlide(1, layout);
//Set the title text
slide.Shapes.Title.TextFrame.TextRange.Text = "Slide Title Heading";
//Set the sub title text
slide.Shapes[2].TextFrame.TextRange.Text = "Slide Title Sub-Heading";
//Write the output to disk
pres.SaveAs("outVSTO.ppt",
PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,
Microsoft.Office.Core.MsoTriState.msoFalse);
}
Aspose.Slides
private static void CreatePresentation()
{
//建立簡報
Presentation pres = new Presentation();
//新增標題投影片
Slide slide = pres.AddTitleSlide();
//設定標題文字
((TextHolder)slide.Placeholders[0]).Text = "Slide Title Heading";
//設定副標題文字
((TextHolder)slide.Placeholders[1]).Text = "Slide Title Sub-Heading";
//寫入輸出至磁碟
pres.Write("outAsposeSlides.ppt");
}