チュートリアル

簡単にライブラリーを使用するためのチュートリアルコレクション

チュートリアル»pptjavaparagraphandtext

Displaying items by tag: pptjavaparagraphandtext

マイクロソフト株式会社によって開発された PowerPoint プレゼンテーションは、視覚的に魅力的でインタラクティブなコンテンツを作成するために使用される多目的なファイル形式です。テキストや画像などの豊富な機能と複数の要素を含んでおり、ビジネスの紹介や学術的なスピーチなど、さまざまなシナリオで強力なツールとなっています。PowerPoint のテキストを編集や操作する必要がある場合、プログラムでテキストを抽出し、新しいファイルに保存することは良い選択です。この記事では、Spire.Presentation for Java を使用して PowerPoint からテキストを抽出する方法を示します。

Spire.Presentation for Java をインストールします

まず、Spire.Presentation for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation</artifactId>
        <version>8.7.3</version>
    </dependency>
</dependencies>

PowerPoint プレゼンテーションからテキストを抽出する

Spire.Presentation for Java では、ParagraphEx.getText() メソッドを使用して、すべてのスライドをループし、各スライドの段落からテキストを抽出することができます。詳細な手順は次のとおりです。

  • Presentation クラスのオブジェクトを作成します。
  • Presentation.loadFromFile() メソッドを使用して PowerPoint プレゼンテーションをロードします。
  • StringBuilder クラスのオブジェクトを作成します。
  • 各スライドの形状と各形状の段落をループします。
  • ParagraphEx.getText() メソッドを呼び出してすべてのスライドからテキストを抽出し、抽出したテキストを StringBuilder オブジェクトに追加します。
  • FileWriter クラスのオブジェクトを作成し、抽出したテキストを新しい .txt ファイルに書き込みます。
  • Java
import com.spire.presentation.*;

import java.io.*;

public class ExtractText {
    public static void main(String[] args) throws Exception {

        //Presentationクラスのオブジェクトを作成する
        Presentation presentation = new Presentation();

        //PowerPointプレゼンテーションをロードする
        presentation.loadFromFile("sample.pptx");

        //StringBuilderオブジェクトを作成する
        StringBuilder buffer = new StringBuilder();

        //各スライドをループしてテキストを抽出する 
        for (Object slide : presentation.getSlides()) {
            for (Object shape : ((ISlide) slide).getShapes()) {
                if (shape instanceof IAutoShape) {
                    for (Object tp : ((IAutoShape) shape).getTextFrame().getParagraphs()) {
                        buffer.append(((ParagraphEx) tp).getText()+"\n");
                    }
                }
            }
        }

        //抽出したテキストを新しい.txtファイルに書き込む
        FileWriter writer = new FileWriter("output/ExtractAllText.txt");
        writer.write(buffer.toString());
        writer.flush();
        writer.close();
        presentation.dispose();
    }
}

Java:PowerPoint からテキストを抽出する方法

特定のスライドからテキストを抽出する

Spire.Presentation for Java では、特定のスライドからテキストを抽出することもサポートしています。テキストを抽出する前に、Presentation.getSlides().get() メソッドを呼び出して、必要なスライドを取得してください。以下に詳細な手順を示します。

  • Presentation クラスのオブジェクトを作成します。
  • Presentation.loadFromFile() メソッドを使用して PowerPoint プレゼンテーションをロードします。
  • StringBuilder クラスのオブジェクトを作成します。
  • Presentation.getSlides().get() メソッドを呼び出して、最初のスライドを取得します。
  • スライドの各形状と各形状の段落をループします。
  • ParagraphEx.getText() メソッドを呼び出して最初のスライドからテキストを抽出し、抽出したテキストを StringBuilder オブジェクトに追加します。
  • FileWriter クラスのオブジェクトを作成し、抽出したテキストを新しい .txt ファイルに書き込みます。
  • Java
import com.spire.presentation.*;

import java.io.*;

public class ExtractText {
    public static void main(String[] args) throws Exception {

        //Presentationクラスのオブジェクトを作成する
        Presentation presentation = new Presentation();

        //PowerPointプレゼンテーションをロードする
        presentation.loadFromFile("sample.pptx");

        //StringBuilderオブジェクトを作成する
        StringBuilder buffer = new StringBuilder();

        //最初のスライドを取得する
        ISlide Slide = presentation.getSlides().get(0);

        //各形状の段落をループしてテキストを抽出する
        for (Object shape : Slide.getShapes()) {
            if (shape instanceof IAutoShape) {
                for (Object tp : ((IAutoShape) shape).getTextFrame().getParagraphs()) {
                    buffer.append(((ParagraphEx) tp).getText()+"\n");
                }
            }
        }

        //抽出したテキストを新しい.txtファイルに書き込む
        FileWriter writer = new FileWriter("output/ExtractSlideText.txt");
        writer.write(buffer.toString());
        writer.flush();
        writer.close();
        presentation.dispose();
    }
}

Java:PowerPoint からテキストを抽出する方法

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。

Published in 段落とテキスト

PowerPoint プレゼンテーションで重要な情報を強調したい場合は、明るい色でハイライトすることができます。これは、視聴者が重要な情報を迅速に取得するのにも役立ちます。この記事では、Spire.Presentation for Java を使用して PowerPoint 内のテキストをハイライトする方法を紹介します。

Spire.Presentation for Java をインストールします

まず、Spire.Presentation for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url> https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation</artifactId>
        <version>8.1.2</version>
    </dependency>
</dependencies>

Java で PowerPoint のテキストをハイライトする

Presentation のテキストをハイライトするには、まずスライドと各スライドの図形をループします。IAutoShape.getTextFrame().highLightText() メソッドを使用して、図形内の指定されたテキストを他の色でハイライトすることができます。以下に詳細な操作手順を示します。

  • Presentation クラスのインスタンスを初期化します
  • Presentation.loadFromFile() メソッドを使用して PowerPoint をロードします。
  • スライドと各スライドの図形をループします。
  • 現在の図形が IAutoShape タイプであることを確認します。
  • 結果が true の場合は、IAutoShape に変換します。
  • TextHighlightingOptions クラスのインスタンスを初期化します。
  • TextHighlightingOptions.setWholeWordsOnly()TextHighlightingOptions.setCaseSensitive() メソッドを使用して、単語全体の表示や大文字と小文字の区別など、テキストの強調表示オプションを設定します。
  • IAutoShape.getTextFrame().highLightText() メソッドを使用して、図形内の特定のテキストを強調表示します。
  • Presentation.saveToFile() メソッドを使用して結果ファイルを保存します。
  • Java
import com.spire.presentation.*;

import java.awt.*;

public class HighlightTextInPPT {
    public static void main(String []args) throws Exception {
        //Presentationクラスのインスタンスを作成する
        Presentation presentation = new Presentation();
        //PowerPointファイルをロードする
        presentation.loadFromFile("Input.pptx");

        //すべてのスライドをループする
        for (int i = 0; i < presentation.getSlides().getCount(); i++)
        {
            //現在のスライドを取得する
            ISlide slide = presentation.getSlides().get(i);
            //スライドの図形をループする
            for (int j = 0; j < slide.getShapes().getCount(); j++)
            {
                //現在の図形がIAutoShapeタイプであることを確認する
                if (slide.getShapes().get(j) instanceof IAutoShape)
                {
                    //図形をIAutoShapeに変換する
                    IAutoShape shape = (IAutoShape)slide.getShapes().get(j);

                    //TextHighLightingOptionsクラスのインスタンスを作成する
                    TextHighLightingOptions options = new TextHighLightingOptions();
                    //テキストのハイライトオプションを設定する
                    options.setCaseSensitive(true);
                    options.setWholeWordsOnly(true);

                    //図形内の特定のテキストをハイライトする
                    shape.getTextFrame().highLightText("Spire.Presentation", Color.YELLOW, options);
                }
            }
        }

        //結果ファイルを保存する
        presentation.saveToFile("HighlightText.pptx", FileFormat.PPTX_2013);

    }
}

Java:PowerPoint 内のテキストをハイライトする方法

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。

Published in 段落とテキスト

PowerPoint プレゼンテーションを作成する際には、いかにスライドを読みやすくするかは非常に重要です。最も一般的な方法の1つは、テキストを番号付き、箇条書きリストとしてフォーマットすることです。この方法は、簡潔で明瞭な方法で情報を表現することができ、読者の注意を引くことができます。この記事では、Spire.Presentation for Java を使用して PowerPoint で番号付きと箇条書きリストを作成する方法を紹介します。

Spire.Presentation for Java をインストールします

まず、Spire.Presentation for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url> https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation</artifactId>
        <version>8.1.2</version>
    </dependency>
</dependencies>

PowerPoint で番号付きリストを作成する

Spire.Presentation では、番号付き、箇条書きリストを作成するために段落の前に数字や行頭記号を追加できます。ParagraphEx.setBulletType() メソッドを使用して、行頭文字のタイプを指定できます。以下は具体的な操作手順です。

  • Presentation オブジェクトを作成します。
  • Presentation.getSlides().get() メソッドを使用して最初のスライドを取得します。
  • ISlide.getShapes().appendShape() メソッドを使用してスライドに図形を追加します。
  • 文字列リスト内のリストの内容を指定します。
  • リストの内容に基づいて段落を作成し、ParagraphEx.setBulletType() メソッドを使用して、これらの段落の行頭文字のタイプを NUMBERED に設定します。
  • ParagraphEx.setBulletStyle() メソッドを使用して、番号付き行頭文字のスタイルを設定します。
  • Presentation.saveToFile() メソッドを使用して、ドキュメントを PowerPoint に保存します。
  • Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class CreateNumberedList {

    public static void main(String[] args) throws Exception {

        //Presentationオブジェクトを作成する
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //最初のスライドを取得する
        ISlide slide = presentation.getSlides().get(0);

        //スライドに図形を追加し、図形のスタイルを設定する
        Rectangle2D rect = new Rectangle2D.Double(50, 50, 300, 200);
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, rect);
        shape.getLine().setFillType(FillFormatType.NONE);
        shape.getFill().setFillType(FillFormatType.NONE);

        //デフォルト段落にテキストを追加する
        ParagraphEx titleParagraph = shape.getTextFrame().getParagraphs().get(0);
        titleParagraph.setText("スキル:");
        titleParagraph.getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID);
        titleParagraph.getTextRanges().get(0).getFill().getSolidColor().setColor(Color.black);
        titleParagraph.setAlignment(TextAlignmentType.LEFT);

        //リスト内容を指定する
        String[] listContent = new String[] {
                " Command-line Unix",
                " Vim",
                " HTML",
                " CSS",
                " Python",
                " JavaScript",
                " SQL"
        };

        //番号付きリストを作成する
        for(int i = 0; i < listContent.length; i ++)
        {
            ParagraphEx paragraph = new ParagraphEx();
            shape.getTextFrame().getParagraphs().append(paragraph);
            paragraph.setText(listContent[i]);
            paragraph.getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID);
            paragraph.getTextRanges().get(0).getFill().getSolidColor().setColor(Color.black);
            paragraph.setBulletType(TextBulletType.NUMBERED);
            paragraph.setBulletStyle(NumberedBulletStyle.BULLET_ARABIC_PERIOD);
        }

        //ドキュメントをPowerPointに保存する
        presentation.saveToFile("NumberedList.pptx", FileFormat.PPTX_2013);
    }
}

Java:PowerPoint で番号付きと箇条書きリストを作成する方法

PowerPoint で記号の箇条書きリストを作成する

記号の箇条書きリストを作成する方法は、番号付きリストを作成する方法とよく似ています。行頭文字のタイプを SYMBOL に設定するだけです。以下に詳細な操作手順を示します。

  • Presentation オブジェクトを作成します。
  • Presentation.getSlides().get() メソッドを使用して最初のスライドを取得します。
  • ISlide.getShapes().appendShape() メソッドを使用してスライドに図形を追加します。
  • 文字列リストのリスト内容を指定します。
  • リストの内容に基づいて段落を作成し、ParagraphEx.setBulletType() メソッドを使用して、段落の行頭文字タイプを SYMBOL に設定します。
  • Presentation.saveToFile() メソッドを使用して、ドキュメントを PowerPoint に保存します。
  • Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class CreateBulletedListWithSymbol {

    public static void main(String[] args) throws Exception {

        //Presentationオブジェクトを作成する
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //最初のスライドを取得する
        ISlide slide = presentation.getSlides().get(0);

        //スライドに図形を追加し、図形のスタイルを設定する
        Rectangle2D rect = new Rectangle2D.Double(50, 50, 350, 200);
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, rect);
        shape.getLine().setFillType(FillFormatType.NONE);
        shape.getFill().setFillType(FillFormatType.NONE);

        //デフォルト段落にテキストを追加する
        ParagraphEx titleParagraph = shape.getTextFrame().getParagraphs().get(0);
        titleParagraph.setText("スキル:");
        titleParagraph.getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID);
        titleParagraph.getTextRanges().get(0).getFill().getSolidColor().setColor(Color.black);
        titleParagraph.setAlignment(TextAlignmentType.LEFT);

        //リスト内容を指定する
        String[] listContent = new String[] {
                " Command-line Unix",
                " Vim",
                " HTML",
                " CSS",
                " Python",
                " JavaScript",
                " SQL"
        };

        //記号の箇条書きリストを作成する
        for(int i = 0; i < listContent.length; i ++)
        {
            ParagraphEx paragraph = new ParagraphEx();
            shape.getTextFrame().getParagraphs().append(paragraph);
            paragraph.setText(listContent[i]);
            paragraph.getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID);
            paragraph.getTextRanges().get(0).getFill().getSolidColor().setColor(Color.black);
            paragraph.setBulletType(TextBulletType.SYMBOL);
        }

        //ドキュメントをPowerPointに保存する
        presentation.saveToFile("SymbolBullets.pptx", FileFormat.PPTX_2013);
    }
}

Java:PowerPoint で番号付きと箇条書きリストを作成する方法

PowerPoint で画像の箇条書きリストを作成する

画像を行頭文字として使用するには、行頭文字のタイプを PICTURE に設定し、画像を BulletPicture オブジェクトに指定します。以下に詳細な操作手順を示します。

  • Presentation オブジェクトを作成します。
  • Presentation.getSlides().get() メソッドを使用して最初のスライドを取得します。
  • ISlide.getShapes().appendShape() メソッドを使用してスライドに図形を追加します。
  • 文字列リストのリスト内容を指定します。
  • リストの内容に基づいて段落を作成し、ParagraphEx.setBulletType() メソッドを使用して、段落の行頭文字のタイプを PICTURE に設定します。
  • Paragraph.getBulletPicture().setEmbedImage() メソッドを使用して、行頭文字に画像を設定します。
  • Presentation.saveToFile() メソッドを使用して、ドキュメントを PowerPoint に保存します。
  • Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;

public class CreateBulletedListWithImage {

    public static void main(String[] args) throws Exception {

        //Presentationオブジェクトを作成する
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //最初のスライドを取得する
        ISlide slide = presentation.getSlides().get(0);

        //スライドに図形を追加し、図形のスタイルを設定する
        Rectangle2D rect = new Rectangle2D.Double(50, 50, 400, 180);
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, rect);
        shape.getLine().setFillType(FillFormatType.NONE);
        shape.getFill().setFillType(FillFormatType.NONE);

        //デフォルト段落にテキストを追加する
        ParagraphEx titleParagraph = shape.getTextFrame().getParagraphs().get(0);
        titleParagraph.setText("To-Do List:");
        titleParagraph.getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID);
        titleParagraph.getTextRanges().get(0).getFill().getSolidColor().setColor(Color.black);
        titleParagraph.setAlignment(TextAlignmentType.LEFT);

        //リスト内容を指定する
        String[] listContent = new String[] {
                " プロジェクトとタスクの定義",
                " タスクに人を割り当てる",
                " タスクの優先度の定義",
                " タスクの進捗状況の追跡",
                " 仕事のまとめ"
        };

        //画像の箇条書きリストを作成する
        BufferedImage image = ImageIO.read(new File("image.jpg"));
        for(int i = 0; i < listContent.length; i ++)
        {
            ParagraphEx paragraph = new ParagraphEx();
            shape.getTextFrame().getParagraphs().append(paragraph);
            paragraph.setText(listContent[i]);
            paragraph.getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID);
            paragraph.getTextRanges().get(0).getFill().getSolidColor().setColor(Color.black);
            paragraph.setBulletType(TextBulletType.PICTURE);
            paragraph.getBulletPicture().setEmbedImage(presentation.getImages().append(image));
        }

        //ドキュメントをPowerPointに保存する
        presentation.saveToFile("ImageBullets.pptx", FileFormat.PPTX_2013);
    }
}

Java:PowerPoint で番号付きと箇条書きリストを作成する方法

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。

Published in 段落とテキスト

プレゼンテーションに商標、著作権、その他の記号を追加するときに、その記号を特定のテキストより少し上または下にしたい場合があります。Microsoft PowerPoint では、記号に上付き文字または下付き文字のフォーマットを適用することで、この効果を実現することができます。この記事では、Spire.Presentation for Java を使用して PowerPoint に上付き文字と下付き文字を追加する方法を紹介します。

Spire.Presentation for Java をインストールします

まず、Spire.Presentation for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url> https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation</artifactId>
        <version>8.1.2</version>
    </dependency>
</dependencies>

PowerPoint に上付き文字と下付き文字を追加する

Spire.Presentation for Java が提供する PortionEx.getFormat().setScriptDistance(float value) メソッドは、テキストに上付き文字と下付き文字のフォーマットを適用することがサポートします。この値は正または負の値に設定できます。正の値が大きいほど、上付き文字がテキストの上に表示されます。負の値が小さいほど、テキストの下に下付き文字が表示されます。以下に詳細な操作手順を示します。

  • Presentationインスタンスを作成し、Presentation.loadFromFile() メソッドを使用して PowerPoint ドキュメントをロードします。
  • Presentation.getSlides().get() メソッドを使用して特定のスライドを取得します。
  • ISlide.getShapes().appendShape() メソッドを使用してスライドに図形を追加し、図形の塗りタイプと線の色を設定します。
  • IAutoShape.getTextFrame() メソッドを使用して図形のテキストフレームにアクセスし、ITextFrameProperties.getParagraphs().clear() メソッドを使用してテキストフレーム内のデフォルトの段落を取り除きます。
  • ParagraphEx クラスを使用して段落を作成し、ParagraphEx.setText() メソッドを使用して段落に標準テキストを追加します。
  • PortionEx クラスを使用してテキストを含むポーションを作成し、PortionEx.getFormat().setScriptDistance(float value) メソッドを使用してテキストに上付き文字または下付き文字の書式設定を適用します。
  • 標準テキスト、上付き文字または下付き文字の色、フォント、フォントサイズを設定します。
  • ITextFrameProperties.getParagraphs().append() メソッドを使用して、図形のテキストフレームに段落をアタッチします。
  • Presentation.saveToFile() メソッドを使用して結果ドキュメントを保存します。
  • Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

import java.awt.*;

public class AddSuperscriptAndSubscript {
    public static void main(String []args) throws Exception {

        //PowerPointドキュメントをロードする
        Presentation presentation = new Presentation();
        presentation.loadFromFile("sample.pptx");

        //最初のスライドを取得する
        ISlide slide = presentation.getSlides().get(0);

        //スライドに図形を追加する
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle(150, 100, 200, 50));
        shape.getFill().setFillType(FillFormatType.NONE);
        shape.getShapeStyle().getLineColor().setColor(Color.white);

        //図形のテキストフレームにアクセスする
        ITextFrameProperties textFrame = shape.getTextFrame();
        //テキストフレームのデフォルト段落を取り除きする
        textFrame.getParagraphs().clear();

        //標準テキストの段落を作成する
        ParagraphEx para = new ParagraphEx();
        para.setText("E=mc");
        
        //上付きテキストのポーションを作成する
        PortionEx tr = new PortionEx("2");
        tr.getFormat().setScriptDistance(40);
        
        //そのポーションを段落に付加する
        para.getTextRanges().append(tr);
        
        para.getTextRanges().append(new PortionEx("\n"));

        //標準テキストの色、フォント、フォントサイズを設定する
        tr = para.getTextRanges().get(0);
        tr.getFill().setFillType(FillFormatType.SOLID);
        tr.getFill().getSolidColor().setColor(new Color(128,0,128));
        tr.setFontHeight(20);
        tr.setLatinFont(new TextFont("Arial"));
        
        //上付きテキストの色とフォントを設定する
        tr = para.getTextRanges().get(1);
        tr.getFill().setFillType(FillFormatType.SOLID);
        tr.getFill().getSolidColor().setColor(Color.BLUE);
        tr.setLatinFont(new TextFont("Arial"));

        //図形のテキストフレームに段落を付加する
        textFrame.getParagraphs().append(para);
        
        //標準テキストの段落を作成する
        para = new ParagraphEx();
        para.setText("X");
        
        //下付きテキストのポーションを作成する
        tr = new PortionEx("100");
        tr.getFormat().setScriptDistance(-25);
        
        //そのポーションを段落に付加する
        para.getTextRanges().append(tr);

        //標準テキストの色、フォント、フォントサイズを設定する
        tr = para.getTextRanges().get(0);
        tr.getFill().setFillType(FillFormatType.SOLID);
        tr.getFill().getSolidColor().setColor(new Color(128,0,128));
        tr.setFontHeight(20);
        tr.setLatinFont(new TextFont("Arial"));
        
        //下付きテキストの色とフォントを設定する
        tr = para.getTextRanges().get(1);
        tr.getFill().setFillType(FillFormatType.SOLID);
        tr.getFill().getSolidColor().setColor(Color.BLUE);
        tr.setLatinFont(new TextFont("Arial"));

        //図形のテキストフレームに段落をアタッチする
        textFrame.getParagraphs().append(para);

        //結果ドキュメントを保存する
        presentation.saveToFile("AddSuperscriptAndSubscript.pptx", FileFormat.PPTX_2013);
    }
}

Java:PowerPoint に上付き文字と下付き文字を追加する方法

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。

Published in 段落とテキスト