Aspose.Slides for .NET(點擊下載)是獨特的演示處理API,使應用程序可以讀取,編寫,修改和轉換PowerPoint演示文稿。做爲獨立的API,它提供了管理PowerPoint關鍵功能的功能,例如管理文本,形狀,表格和動畫,向幻燈片添加音頻和視頻,預覽幻燈片等等。ide
Aspose.Slides for .NET更新至最新版v19.9,如今有一些很是有趣且實用的功能值得爲你們講解一下,好比經過「替代文本」來隱藏形狀,接下來經過一些簡單的示例來爲你們說明一下!動畫
首先,須要使用「替代文本」屬性來標識所需的形狀。而後,使用如下示例在API中隱藏形狀的代碼。spa
//文檔目錄的路徑。 string dataDir = RunExamples.GetDataDir_Shapes(); //實例化表示PPTX的Presentation類 Presentation pres = new Presentation(); //獲取第一張幻燈片 ISlide sld = pres.Slides[0]; //添加矩形的自動形狀 IShape shp1 = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 40, 150, 50); IShape shp2 = sld.Shapes.AddAutoShape(ShapeType.Moon, 160, 40, 150, 50); String alttext = "User Defined"; int iCount = sld.Shapes.Count; for (int i = 0; i < iCount; i++) { AutoShape ashp = (AutoShape)sld.Shapes[i]; if (String.Compare(ashp.AlternativeText, alttext, StringComparison.Ordinal) == 0) { ashp.Hidden = true; } } //將演示文稿保存到磁盤 pres.Save(dataDir + "Hiding_Shapes_out.pptx", SaveFormat.Pptx);
與此相似的基於Java的示例:orm
//文檔目錄的路徑。 String dataDir = Utils.getDataDir(HidingTheShapesFromSlide.class); Presentation presentation1 = new Presentation(); ISlide slide = presentation1.getSlides().get_Item(0); for (int i = 0; i < slide.getShapes().size(); i++) { IAutoShape ashp = (IAutoShape) slide.getShapes().get_Item(i); ashp.setHidden(true); } presentation1.save(dataDir + "sample_output.pptx", SaveFormat.Pptx);
與此相似的基於C++的示例:視頻
//文檔目錄的路徑。 const String outPath = u"../out/Hidingshapes_out.pptx"; const String templatePath = u"../templates/ConnectorLineAngle.pptx"; //加載所需的演示文稿 SharedPtr<Presentation> pres = MakeObject<Presentation>(); //訪問第一張幻燈片 SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0); //訪問選定幻燈片的形狀集合 SharedPtr<IShapeCollection> shapes = slide->get_Shapes(); //如今從頭開始爲現有形狀建立效果「 PathFootball」。 SharedPtr<IAutoShape> autoShape1 = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 40, 150, 50); SharedPtr<IAutoShape> autoShape2 = slide->get_Shapes()->AddAutoShape(ShapeType::Moon, 160, 40, 150, 50); String alttext = u"User Defined"; int iCount = slide->get_Shapes()->get_Count(); for (int i = 0; i < iCount; i++) { //訪問添加的形狀 SharedPtr<AutoShape> ashape = DynamicCast<Aspose::Slides::AutoShape>(slide->get_Shapes()->idx_get(i)); if (String::Compare(ashape->get_AlternativeText(), alttext, StringComparison::Ordinal) == 0) { ashape->set_Hidden(true); } } //將PPTX寫入磁盤 pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);