翻譯|使用教程|編輯:李顯亮|2021-04-12 11:09:25.920|閱讀 401 次
概述:PowerPoint提供了許多形狀,例如直線,橢圓,矩形等。在本文中,將學(xué)習(xí)如何在PowerPoint演示文稿中自動(dòng)操縱形狀。特別是,本文將介紹如何使用Java在PowerPoint演示文稿中添加,連接,克隆或刪除形狀。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
PowerPoint演示文稿中的形狀用于闡述特定點(diǎn)或創(chuàng)建諸如流程圖之類的圖。此外,形狀的包含使該演示文稿更具吸引力。因此,PowerPoint提供了許多形狀,例如直線,橢圓,矩形等。在本文中,將學(xué)習(xí)如何在PowerPoint演示文稿中自動(dòng)操縱形狀。特別是,本文將介紹如何使用Java在PowerPoint演示文稿中添加,連接,克隆或刪除形狀。
為了使用PowerPoint形狀,我們將使用Aspose.Slides。它是一個(gè)功能強(qiáng)大的Java API,可讓您無(wú)縫操作PowerPoint演示文稿。特別是,API使您可以創(chuàng)建,修改,閱讀和轉(zhuǎn)換演示文稿文檔。
>>你可以點(diǎn)擊這里下載Aspose.Slides for java最新版測(cè)試體驗(yàn)。
PowerPoint支持各種形狀,您可以將它們添加到演示文稿幻燈片中。因此,Aspose.Slides for Java支持以下形狀類型:
Connector、Ellipse、Flash、Group、Image、Line、Paragraph、Picture、Frame、Portion、Rectangle等。
Java的Aspose.Slides提供ShapeType類來(lái)指定要添加的形狀的類型。以下是使用Java在PowerPoint演示文稿中添加特定形狀的步驟。
下面的代碼示例演示如何使用Java將形狀添加到PowerPoint演示文稿中。
// Instantiate Presentation class that represents the PPTX Presentation pres = new Presentation(); // Get the first slide ISlide sld = pres.getSlides().get_Item(0); // Add AutoShape of ellipse type sld.getShapes().addAutoShape(ShapeType.Ellipse, 100, 150, 150, 100); // Write the PPTX file to disk pres.save("add_shape.pptx", SaveFormat.Pptx);
以下是執(zhí)行此代碼后將獲得的輸出。
連接器是用于連接兩個(gè)形狀的線。此外,連接器可以是直線或曲線。以下是在兩個(gè)PowerPoint形狀之間添加連接器的步驟。
下面的代碼示例演示如何使用Java在PowerPoint中的兩個(gè)形狀之間添加連接器。
// Instantiate Presentation class that represents the PPTX file Presentation input = new Presentation(); // Access shapes collection for selected slide IShapeCollection shapes = input.getSlides().get_Item(0).getShapes(); // Add Autoshape Ellipse IAutoShape ellipse = shapes.addAutoShape(ShapeType.Ellipse, 0, 100, 100, 100); // Add Autoshape Rectangle IAutoShape rectangle = shapes.addAutoShape(ShapeType.Rectangle, 100, 300, 100, 100); // Add connector shape to slide shape collection IConnector connector = shapes.addConnector(ShapeType.BentConnector2, 0, 0, 10, 10); // Join Shapes to connectors connector.setStartShapeConnectedTo(ellipse); connector.setEndShapeConnectedTo(rectangle); connector.reroute(); // Save Presentation input.save("connect_shape.pptx", SaveFormat.Pptx);
以下是連接形狀后PowerPoint演示文稿的屏幕截圖。
您也可以克隆PowerPoint形狀以創(chuàng)建其副本。以下是執(zhí)行此操作的步驟。
下面的代碼示例演示如何使用Java添加PowerPoint形狀的克隆。
// Instantiate Presentation class that represents the PPTX Presentation pres = new Presentation(); // Get the first slide ISlide sld = pres.getSlides().get_Item(0); // Add AutoShape of rectangle type IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 75, 150); // Rotate the shape to 90 degree shp.setRotation(90); // Write the PPTX file to disk pres.save("clone_shape.pptx", SaveFormat.Pptx);
您也可以使用Aspose.Slides for Java從幻燈片中刪除PowerPoint形狀。以下是從形狀集合中刪除PowerPoint形狀的步驟。
下面的代碼示例演示如何使用Java從幻燈片中刪除PowerPoint形狀。
// Load presentation Presentation presentation1 = new Presentation("clone_shape.pptx"); // Get slide ISlide slide = presentation1.getSlides().get_Item(0); // Shape text to find the shape String alttext = "User Defined"; // Get number of shapes int iCount = slide.getShapes().size(); // Loop through shapes for (int i = 0; i < iCount; i++) { // Get shape IAutoShape ashp = (IAutoShape) slide.getShapes().get_Item(0); if (ashp.getAlternativeText().compareTo(alttext) == 0) { // Remove shape slide.getShapes().remove(ashp); } } presentation1.save("remove_shape.pptx", SaveFormat.Pptx);
如果你想試用Aspose的全部完整功能,可聯(lián)系在線客服獲取30天臨時(shí)授權(quán)體驗(yàn)。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn