This article demonstrates how to add built-in document properties and custom document properties in Excel using Spire.XLS for Java.
Add built-in document properties
import com.spire.xls.ExcelVersion; import com.spire.xls.Workbook; public class BuiltinProperties { public static void main(String[] args){ //Load an Excel file Workbook workbook = new Workbook(); workbook.loadFromFile("input.xlsx"); //Add built-in document properties to the file workbook.getDocumentProperties().setTitle("Add Document Properties"); workbook.getDocumentProperties().setSubject("Spire.XLS for Java Demo"); workbook.getDocumentProperties().setAuthor("Shaun"); workbook.getDocumentProperties().setManager("Bill"); workbook.getDocumentProperties().setCompany("E-iceblue"); workbook.getDocumentProperties().setCategory("Spire.XLS for Java"); workbook.getDocumentProperties().setKeywords("Excel Document Properties"); //Save the resultant file workbook.saveToFile("BuiltinDocumentProperties.xlsx", ExcelVersion.Version2013); } }
Add 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){ //Load an Excel file Workbook workbook = new Workbook(); workbook.loadFromFile("input.xlsx"); //Add custom properties to the file workbook.getCustomDocumentProperties().add("_MarkAsFinal", true); workbook.getCustomDocumentProperties().add("The Editor", "E-iceblue"); workbook.getCustomDocumentProperties().add("Phone number", 81705109); workbook.getCustomDocumentProperties().add("Revision number", 7.12); workbook.getCustomDocumentProperties().add("Revision date", new Date()); //Save the resultant file workbook.saveToFile("CustomDocumentProperties.xlsx", ExcelVersion.Version2013); } }