Java sets Excel document properties

Excel document properties are descriptive information and include items such as author, title, subject, keywords, and categories. Setting properties for Excel documents allows users to manage Excel documents more conveniently and quickly. This article will show you how to use Free Spire.XLS for Java to set built-in and custom document properties in an Excel document.

** Environment configuration: ** ** Method 1: ** Free Spire.XLS for Java Download the package, unzip it, and create the lib folder. Import the Spire.Xls.jar package as a dependency into your Java application.

** Method 2: ** You can also install the JAR package directly from the Maven repository The code that makes up the pom.xml file is:

<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>

** Set built-in document properties: **

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

public class BuiltinProperties {
    public static void main(String[] args){
        //Import an Excel document
        Workbook workbook = new Workbook();
        workbook.loadFromFile("test.xlsx");

        //Set document title, subject, author, and other built-in document attributes
        workbook.getDocumentProperties().setTitle("Set document properties");
        workbook.getDocumentProperties().setSubject("purchase order");
        workbook.getDocumentProperties().setAuthor("AAA");
        workbook.getDocumentProperties().setManager("BBB");
        workbook.getDocumentProperties().setCompany("Company C");
        workbook.getDocumentProperties().setCategory("Spending");
        workbook.getDocumentProperties().setKeywords("Excel document properties");

        //Save result file
        workbook.saveToFile("BuiltinDocumentProperties.xlsx", ExcelVersion.Version2013);
    }
}

in.jpg

** Set custom document properties: **

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

import java.util.Date;

public class CustomProperties {
    public static void main(String[] args){
        //Import an Excel document
        Workbook workbook = new Workbook();
        workbook.loadFromFile("Input.xlsx");

        //Add custom document properties to your document
        workbook.getCustomDocumentProperties().add("_MarkAsFinal", true);
        workbook.getCustomDocumentProperties().add("To edit", "AAA");
        workbook.getCustomDocumentProperties().add("Contact number", 81705109);
        workbook.getCustomDocumentProperties().add("date", new Date());

        //Save result file
        workbook.saveToFile("CustomDocumentProperties.xlsx", ExcelVersion.Version2013);
    }
}

cu.png

Recommended Posts

Java sets Excel document properties
Java adds and reads Excel formulas