JavaはPPTでSmartArtグラフィックのテキストコンテンツを抽出します

(ツールを使用:Java用の無料のSpire.Presentation)

JARパッケージのインポート

方法1: Free Spire.Presentation for Javaパッケージをダウンロードして解凍し、依存関係としてlibフォルダーにあるjarパッケージをJavaアプリケーションに直接インポートします。

方法2: Mavenウェアハウスを介してjarパッケージをインストールし、pom.xmlファイルのコードを次のように構成します。

<リポジトリ>
    <リポジトリ>
        <id> com.e-iceblue </ id>
        <url> http://repo.e-iceblue.cn/repository/maven-public/ </ url>
    </リポジトリ>
</リポジトリ>
<依存関係>
    <依存関係>
        <groupId> e-iceblue </ groupId>
        <artifactId> spire.presentation.free </ artifactId>
        <バージョン> 3.9.0 </バージョン>
    </依存性>
</依存関係>

Javaコード例

インポートcom.spire.presentation.Presentation;
インポートcom.spire.presentation.diagrams.ISmartArt;
java.ioをインポートします。*;

// javaプロジェクトwww.fhadmin.org
パブリッククラスextractTextFromSmartArt {
    public static void main(String [] args)は例外をスローします{
        プレゼンテーションプレゼンテーション= new Presentation();
        present.loadFromFile( "SmartArt.pptx");

        //新しいtxtドキュメント
        文字列の結果= "output / extractTextFromSmartArt.txt";
        ファイルfile = new File(result);
        if(file.exists()){
            file.delete();
        }
        file.createNewFile();
        FileWriter fw = new FileWriter(file、true);
        BufferedWriter bw = new BufferedWriter(fw);

        bw.write( "次のコンテンツはSmartArtから抽出されたテキストです:" + "\ r \ n");

        //すべてのスライドをトラバースして、SmartArtグラフィックを取得します。
        for(int i = 0; i <presentation.getSlides()。getCount(); i ++)
        {{
            for(int j = 0; j <presentation.getSlides()。get(i).getShapes()。getCount(); j ++)
            {{
                if(presentation.getSlides()。get(i).getShapes()。get(j)instanceof ISmartArt)
                {{
                    ISmartArt smartArt =(ISmartArt)presentation.getSlides()。get(i).getShapes()。get(j);

                    // SmartArtでテキストを抽出します
                    for(int k = 0; k <smartArt.getNodes()。getCount(); k ++)
                    {{
                        bw.write(smartArt.getNodes()。get(k).getTextFrame()。getText()+ "\ r \ n");
                    }
                }
            }
        }
        bw.flush();
        bw.close();
        fw.close();

    }
}

コード実行結果:


おすすめ

転載: blog.51cto.com/14622073/2545331