Hello World プレゼンテーションドキュメントの作成方法
Contents
[
Hide
]
新しい Aspose.Slides for Java API がリリースされ、これによりこの単一の製品がゼロから PowerPoint ドキュメントを生成し、既存のドキュメントを編集する機能をサポートするようになりました。
レガシーコードのサポート
Aspose.Slides for Java 13.x より前のバージョンで開発されたレガシーコードを使用するためには、コードにいくつかの小さな変更を加える必要がありますが、その後は以前と同様に動作します。古い Aspose.Slides for Java の Aspose.Slide および Aspose.Slides.Pptx 名前空間に存在していたすべてのクラスは、現在は単一の Aspose.Slides 名前空間に統合されました。以下のレガシー Aspose.Slides API を使用して Hello World プレゼンテーションドキュメントを作成するためのシンプルなコードスニペットを確認し、新しい統合 API への移行手順を確認してください。
レガシー Aspose.Slides for Java のアプローチ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Instantiate a Presentation object that represents a PPT file | |
Presentation pres = new Presentation(); | |
//Create a License object | |
License license = new License(); | |
//Set the license of Aspose.Slides for Java to avoid the evaluation limitations | |
license.setLicense("Aspose.Slides.lic"); | |
//Adding an empty slide to the presentation and getting the reference of | |
//that empty slide | |
Slide slide = pres.addEmptySlide(); | |
//Adding a rectangle (X=2400, Y=1800, Width=1000 & Height=500) to the slide | |
com.aspose.slides.Rectangle rect = slide.getShapes().addRectangle(2400, 1800, 1000, 500); | |
//Hiding the lines of rectangle | |
rect.getLineFormat().setShowLines(false); | |
//Adding a text frame to the rectangle with "Hello World" as a default text | |
rect.addTextFrame("Hello World"); | |
//Removing the first slide of the presentation which is always added by | |
//Aspose.Slides for Java by default while creating the presentation | |
pres.getSlides().removeAt(0); | |
//Writing the presentation as a PPT file | |
pres.write("C:\\hello.ppt"); | |
新しい Aspose.Slides for Java 14.x.x のアプローチ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CreateAPresentation.class); | |
// Instantiate Presentation | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = (ISlide) pres.getSlides().get_Item(0); | |
// Add an AutoShape of Rectangle type | |
IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 150, 50); | |
// Add ITextFrame to the Rectangle | |
ashp.addTextFrame("Hello World"); | |
// Change the text color to Black (which is White by default) | |
ashp.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat() | |
.setFillType(FillType.Solid); | |
ashp.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat() | |
.getSolidFillColor().setColor(java.awt.Color.BLACK); | |
// Change the line color of the rectangle to White | |
ashp.getShapeStyle().getLineColor().setColor(java.awt.Color.WHITE); | |
// Remove any fill formatting in the shape | |
ashp.getFillFormat().setFillType(FillType.NoFill); | |
// Save the presentation to disk | |
pres.save(dataDir + "HelloWorld.pptx", com.aspose.slides.SaveFormat.Pptx); |