この簡単なトピックでは、MS Windows、macOS、またはUbuntuオペレーティングシステムでJavaを使用してPowerPoint Presentationを作成する方法について説明します。このトピックでは、環境をセットアップするための詳細な手順について説明し、* JavaPPT*プレゼンテーションで数行の簡単なコードを使用して生成できます。
JavaでPowerPointプレゼンテーションを生成する手順
- MavenリポジトリからAspose.Slides for Javaをダウンロードしてインストールします
- Presentationクラスオブジェクトをインスタンス化して、空のプレゼンテーションを作成します
- 空白のスライドを作成し、それをプレゼンテーションスライドコレクションに追加します
- AddAutoShapeメソッドを使用して、新しく作成したスライドに長方形の図形を挿入します
- addTextFrameメソッドを使用してテキストフレームを挿入し、テキスト関連のプロパティを設定します
- プレゼンテーションをPPTX形式でディスクに保存します
- Javaの前述の手順では、PowerPointに依存せずに、単純なAPIインターフェイスを使用してディスク上にPPTXファイル*を作成します。最初に、Presentationクラスインスタンスを使用して空のプレゼンテーションが作成され、続いてプレゼンテーション内に空白のスライドが追加されます。次に、図形の内側にテキストフレームが追加され、それぞれのテキストプロパティが設定されてから、saveメソッドを使用してプレゼンテーションがディスクに保存されます。
Javaを使用してPowerPointプレゼンテーションを作成するコード
import com.aspose.slides.FillType; | |
import com.aspose.slides.IAutoShape; | |
import com.aspose.slides.IPortionFormat; | |
import com.aspose.slides.ISlide; | |
import com.aspose.slides.ITextFrame; | |
import com.aspose.slides.License; | |
import com.aspose.slides.NullableBool; | |
import com.aspose.slides.Presentation; | |
import com.aspose.slides.SaveFormat; | |
import com.aspose.slides.ShapeType; | |
import com.aspose.slides.SlideLayoutType; | |
import java.awt.Color; | |
public class CreatePresentation { | |
public static void main(String[] args){ | |
// Setting the linence for the product | |
License SlidesLicense = new License(); | |
SlidesLicense.setLicense("Aspose.Total.lic"); | |
// Create an empty presentation using the Presentation class instance | |
Presentation presentation = new Presentation(); | |
// Insert a Blank slide inside the presentation | |
ISlide slide = presentation.getSlides().addEmptySlide(presentation.getLayoutSlides() | |
.getByType(SlideLayoutType.Blank)); | |
// Add an auto-shape of Rectangle type | |
IAutoShape autoShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 300, 0); | |
// Fill the shape with Green color | |
autoShape.getFillFormat().setFillType(FillType.Solid); | |
autoShape.getFillFormat().getSolidFillColor().setColor(Color.GREEN); | |
// Adding some text inside the shape | |
ITextFrame textFrame = autoShape.addTextFrame("This is Aspose.Slides"); | |
// Set text related properties | |
IPortionFormat portionFormat = textFrame.getParagraphs().get_Item(0) | |
.getPortions().get_Item(0).getPortionFormat(); | |
portionFormat.getFillFormat().setFillType(FillType.Solid); | |
portionFormat.getFillFormat().getSolidFillColor().setColor(Color.RED); | |
portionFormat.setFontBold(NullableBool.True); | |
portionFormat.setFontItalic(NullableBool.True); | |
portionFormat.setFontHeight(14); | |
// Save the generated presentation on the disk | |
presentation.save("NewJavaPresentation.pptx", SaveFormat.Pptx); | |
} | |
} |
- Javaプレゼンテーション*では、上記の例に示すように、数行のコードを使用して生成できます。 SaveFormat列挙子を使用して、PPT、PPS、PPSX、ODP、POT、POTXなどの他の形式でプレゼンテーションを保存することもできます。プレゼンテーション内のテキストは、ParagraphFormatクラスとPortionFormatクラスで公開されているさまざまなオプションを使用してカスタマイズできます。これには、テキストの折り返し、テキストの自動調整、インデント、余白、箇条書き、テキストの強調表示、取り消し線などのオプションの設定が含まれます。
このトピックでは、さまざまな形式でJavaPowerPointプレゼンテーションを使用して作成する方法を学習しました。プレゼンテーションスライドをSVGに変換することに興味がある場合は、Javaを使用してPPTXをSVGに変換する方法の記事に記載されている詳細にアクセスしてください。