本文将介绍如何使用spire.xls for java给excel文档设置内置文档属性和自定义文档属性。
设置内置文档属性
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("input.xlsx");
//给文档设置标题、主题、作者等内置文档属性
workbook.getdocumentproperties().settitle("设置文档属性");
workbook.getdocumentproperties().setsubject("spire.xls for java demo");
workbook.getdocumentproperties().setauthor("张丽");
workbook.getdocumentproperties().setmanager("王刚");
workbook.getdocumentproperties().setcompany("e-iceblue");
workbook.getdocumentproperties().setcategory("spire.xls for java");
workbook.getdocumentproperties().setkeywords("excel文档属性");
//保存结果文档
workbook.savetofile("builtindocumentproperties.xlsx", excelversion.version2013);
}
}
设置自定义文档属性
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("编辑", "e-iceblue");
workbook.getcustomdocumentproperties().add("联系电话", 81705109);
workbook.getcustomdocumentproperties().add("更新日期", new date());
//保存结果文档
workbook.savetofile("customdocumentproperties.xlsx", excelversion.version2013);
}
}