翻譯|使用教程|編輯:張瑩心|2021-10-08 10:03:04.467|閱讀 295 次
概述:演示文稿中的 SmartArt 用于以視覺形式提供信息。有時,選擇使簡單的文本更具吸引力。而在其他情況下,它用于演示流程圖、流程、不同實體之間的關系等。在本文中,您將學習如何使用 C# 以編程方式在 PowerPoint 演示文稿中創建 SmartArt。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
演示文稿中的 SmartArt 用于以視覺形式提供信息。有時,選擇使簡單的文本更具吸引力。而在其他情況下,它用于演示流程圖、流程、不同實體之間的關系等。在本文中,您將學習如何使用 C# 以編程方式在 PowerPoint 演示文稿中創建 SmartArt。
為了在 PowerPoint 演示如何使用 C# 以編程方式在 PowerPoint 演示文稿中創建 SmartArt。,我們將使用Aspose.Slides for .NET,它是一個強大且功能豐富的 API,用于在 .NET 應用程序中創建和操作演示文稿。
>>你可以點擊這里下載Aspose.Slides 最新版測試體驗。
在 PowerPoint 中創建 SmartArt 的 .NET API
為了在 PowerPoint 演示文稿中使用 SmartArt,我們將使用 Aspose.Slides for .NET。它是一個強大的類庫,用于創建和操作 PowerPoint 和 OpenOffice 演示文稿。您可以通過NuGet安裝 API 或 下載 其 DLL。
PM> Install-Package Aspose.Slides.NET
使用 C# 在 PowerPoint 中創建 SmartArt 形狀
Aspose.Slides for .NET 提供了在演示文稿中創建 SmartArt 形狀的最簡單方法。為了演示,讓我們使用 C# 在 PowerPoint 演示文稿中從頭開始創建 SmartArt 形狀。
以下代碼示例展示了如何在 PowerPoint 演示文稿中創建 SmartArt 形狀。
// Create a presentation or load existing one using (Presentation pres = new Presentation()) { // Access the presentation slide ISlide slide = pres.Slides[0]; // Add SmartArt Shape ISmartArt smart = slide.Shapes.AddSmartArt(0, 0, 400, 400, SmartArtLayoutType.BasicBlockList); smart.AllNodes[0].TextFrame.Text = "First Block"; smart.AllNodes[1].TextFrame.Text = "Second Block"; // Save presentation pres.Save("SimpleSmartArt_out.pptx", Aspose.Slides.Export.SaveFormat.Pptx); }
以下屏幕截圖顯示了上述代碼示例的輸出。
使用 C# 在 PowerPoint 中訪問 SmartArt 形狀
您還可以訪問現有 PowerPoint 演示文稿中的 SmartArt 形狀。訪問后,您可以根據需要修改它們。以下是使用 C# 訪問 PowerPoint 演示文稿中的 SmartArt 形狀的步驟。
以下代碼示例展示了如何訪問 PowerPoint 演示文稿中的 SmartArt 形狀。
// Load the presentation using (Presentation pres = new Presentation("AccessSmartArtShape.pptx")) { // Iterate through every shape inside desired slide foreach (IShape shape in pres.Slides[0].Shapes) { // Check if shape is of SmartArt type if (shape is ISmartArt) { // Typecast shape to SmartArt ISmartArt smart = (ISmartArt)shape; System.Console.WriteLine("Shape Name:" + smart.Name); // Checking SmartArt Layout //if (smart.Layout == SmartArtLayoutType.BasicBlockList) //{ // Console.WriteLine("Do some thing here...."); //} } } }
使用 C# 更改 SmartArt 形狀的樣式
訪問 SmartArt 形狀后,您也可以更改其樣式。以下步驟演示了如何使用 C# 更改 PowerPoint 演示文稿中 SmartArt 形狀的樣式。
以下代碼示例展示了如何更改 PowerPoint 演示文稿中 SmartArt 形狀的樣式。
// Load presentation using (Presentation presentation = new Presentation("AccessSmartArtShape.pptx")) { // Traverse through every shape inside first slide foreach (IShape shape in presentation.Slides[0].Shapes) { // Check if shape is of SmartArt type if (shape is ISmartArt) { // Typecast shape to SmartArt ISmartArt smart = (ISmartArt)shape; // Check SmartArt style if (smart.QuickStyle == SmartArtQuickStyleType.SimpleFill) { // Change SmartArt Style smart.QuickStyle = SmartArtQuickStyleType.Cartoon; } // Check SmartArt color type if (smart.ColorStyle == SmartArtColorType.ColoredFillAccent1) { // Change SmartArt color type smart.ColorStyle = SmartArtColorType.ColorfulAccentColors; } } } // Save Presentation presentation.Save("ChangeSmartArtStyle_out.pptx", SaveFormat.Pptx); }
如果你想試用Aspose的全部完整功能,可聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn