0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JavaはExcelドキュメントプロパティを設定します

Posted at

Excelドキュメントプロパティは説明的な情報であり、作成者、タイトル、件名、キーワード、カテゴリなどのアイテムが含まれます。Excelドキュメントのプロパティを設定することで、ユーザーがExcelドキュメントをより便利かつ迅速に管理できるようになります。この記事では、Free Spire.XLS for Javaを使用して、Excel文書に組み込みのドキュメントプロパティとカスタムドキュメントプロパティを設定する方法を紹介します。

環境構成:
方法1: Free Spire.XLS for Javaパッケージをダウンロードして解凍し、libフォルダーのSpire.Xls.jarパッケージを依存関係としてJavaアプリケーションにインポートします。

方法2: Mavenリポジトリから直接JARパッケージをインストールすることもできますpom.xmlファイルを構成するコードは次のとおりです。

<repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls.free</artifactId>
        <version>2.2.0</version>
    </dependency>
</dependencies>

組み込みのドキュメントプロパティを設定します:

import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;

public class BuiltinProperties {
    public static void main(String[] args){
        //Excelドキュメントを読み込む
        Workbook workbook = new Workbook();
        workbook.loadFromFile("test.xlsx");

        //ドキュメントのタイトル、件名、作成者、およびその他の組み込みドキュメント属性を設定する
        workbook.getDocumentProperties().setTitle("ドキュメントプロパティを設定する");
        workbook.getDocumentProperties().setSubject("注文書");
        workbook.getDocumentProperties().setAuthor("AAA");
        workbook.getDocumentProperties().setManager("BBB");
        workbook.getDocumentProperties().setCompany("C社");
        workbook.getDocumentProperties().setCategory("支出");
        workbook.getDocumentProperties().setKeywords("Excelドキュメントのプロパティ");

        //結果ファイルを保存
        workbook.saveToFile("BuiltinDocumentProperties.xlsx", ExcelVersion.Version2013);
    }
}

in.jpg

カスタムドキュメントプロパティを設定します:

import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;

import java.util.Date;

public class CustomProperties {
    public static void main(String[] args){
        //Excelドキュメントを読み込む
        Workbook workbook = new Workbook();
        workbook.loadFromFile("Input.xlsx");

        //ドキュメントにカスタムドキュメントプロパティを追加する
        workbook.getCustomDocumentProperties().add("_MarkAsFinal", true);
        workbook.getCustomDocumentProperties().add("編集する", "AAA");
        workbook.getCustomDocumentProperties().add("連絡先番号", 81705109);
        workbook.getCustomDocumentProperties().add("日付", new Date());

        //結果ファイルを保存
        workbook.saveToFile("CustomDocumentProperties.xlsx", ExcelVersion.Version2013);
    }
}

cu.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?