チュートリアル

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

チュートリアル»Java»Spire.Presentation for Java»文書操作»Java:PowerPoint ドキュメントのプロパティの追加、取得、削除
2023-08-09

Java: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 では、Presentation.getDocumentProperty() メソッドでドキュメントプロパティを取得した後、IDocumentProperty クラスのメソッドでプレゼンテーションのドキュメントプロパティを設定、取得することができます。PowerPoint プレゼンテーションにドキュメントプロパティを追加するための詳細な手順は次のとおりです。

  • Presentation クラスのオブジェクトを作成します。
  • Presentation.loadFromFile() メソッドを使用してプレゼンテーション ファイルを読み込みます。
  • Presentation.getDocumentProperty() メソッドを使用してプレゼンテーションのドキュメント プロパティを取得します。
  • IDocumentProperty クラスのメソッドを使用してドキュメント プロパティを設定します。
  • Presentation.saveToFile() メソッドを使用してプレゼンテーションを保存します。
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.IDocumentProperty;
import com.spire.presentation.Presentation;

public class addPresentationProperties {
    public static void main(String[] args) throws Exception {
        //Presentationクラスのオブジェクトを作成する
        Presentation presentation = new Presentation();

        //プレゼンテーションを読み込む
        presentation.loadFromFile("サンプル.pptx");

        //プレゼンテーションのドキュメント プロパティを取得し、プロパティ情報を設定する
        IDocumentProperty property = presentation.getDocumentProperty();
        property.setTitle("年次経営分析報告書");
        property.setSubject("経営分析");
        property.setAuthor("文室 信子");
        property.setManager("松尾 敏紀");
        property.setCompany("E-iceblue");
        property.setCategory("報告書");
        property.setKeywords("事業分析; 四半期事業データ; 成長データ");
        property.setComments("報告書は改訂され、最終版となった。");

        //プレゼンテーションを保存する
        presentation.saveToFile("プロパティの追加.pptx", FileFormat.AUTO);
        presentation.dispose();
    }
}

Java:PowerPoint ドキュメントのプロパティの追加、取得、削除

PowerPoint プレゼンテーションからドキュメント プロパティを取得

PowerPoint プレゼンテーションからドキュメントプロパティを取得するための詳細な手順は以下のとおりです。

  • Presentation クラスのオブジェクトを作成します。
  • Presentation.loadFromFile() メソッドを使用してプレゼンテーション ファイルを読み込みます。
  • Presentation.getDocumentProperty() メソッドを使用して、プレゼンテーションのプロパティを取得します。
  • IDocumentProperty クラスのメソッドを使用してプロパティ情報を取得し、テキストファイルに書き込みます。
  • Java
import com.spire.presentation.IDocumentProperty;
import com.spire.presentation.Presentation;

import java.io.FileWriter;

public class retrievePresentationProperties {
    public static void main(String[] args) throws Exception {
        //Presentationクラスのオブジェクトを作成する
        Presentation presentation = new Presentation();

        //プレゼンテーションを読み込む
        presentation.loadFromFile("プロパティの追加.pptx");

        //プレゼンテーションのドキュメント プロパティを取得する
        IDocumentProperty property = presentation.getDocumentProperty();

        //文書のプロパティ データを取得し、テキスト ファイルに書き込む
        String properties = "タイトル:" + property.getTitle() + "\r\n"
                + "サブタイトル:" + property.getSubject() + "\r\n"
                + "作成者:" + property.getAuthor() + "\r\n"
                + "管理者:" + property.getManager() + "\r\n"
                + "会社名:" + property.getCompany() + "\r\n"
                + "分類:" + property.getCategory() + "\r\n"
                + "キーワード:" + property.getKeywords() + "\r\n"
                + "コメント:" + property.getComments();
        FileWriter presentationProperties = new FileWriter("プロパティの取得.txt");
        presentationProperties.write(properties);
        presentationProperties.close();
    }
}

Java:PowerPoint ドキュメントのプロパティの追加、取得、削除

PowerPoint プレゼンテーションのドキュメント プロパティを削除

プレゼンテーションからドキュメント プロパティを削除するのは、プロパティを追加するのと似ています。プロパティ データを空値に設定するだけで、ドキュメント プロパティを削除することができます。詳細は以下の通りです。

  • Presentation クラスのオブジェクトを作成します。
  • Presentation.loadFromFile() メソッドを使用してプレゼンテーション ファイルを読み込みます。
  • Presentation.getDocumentProperty() メソッドを使用して、プレゼンテーションのドキュメント プロパティを取得します。
  • IDocumentProperty クラスのメソッドを使用して、ドキュメント プロパティを空白に設定します。
  • Presentation.saveToFile() メソッドを使用してプレゼンテーションを保存します。
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.IDocumentProperty;
import com.spire.presentation.Presentation;

public class deletePresentationProperties {
    public static void main(String[] args) throws Exception {
        //Presentationクラスのオブジェクトを作成する
        Presentation presentation = new Presentation();

        //プレゼンテーションを読み込む
        presentation.loadFromFile("プロパティの追加.pptx");

        //プレゼンテーションのドキュメント プロパティを取得し、プロパティを空白に設定する
        IDocumentProperty property = presentation.getDocumentProperty();
        property.setTitle(" ");
        property.setSubject("");
        property.setAuthor("");
        property.setManager("");
        property.setCompany("");
        property.setCategory("");
        property.setKeywords("");
        property.setComments("");

        //プレゼンテーションを保存する
        presentation.saveToFile("プロパティの削除.pptx", FileFormat.AUTO);
        presentation.dispose();
    }
}

Java:PowerPoint ドキュメントのプロパティの追加、取得、削除

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

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

Read 345 times