标签:author input epo xls rop document 结果 strong rom
Excel文档属性是一些描述性的信息,它包括作者、标题、主题、关键词、类别等项目。通过设置Excel文档属性,可以帮助用户更加方便快捷的管理Excel文档。本文将介绍如何使用Free Spire.XLS for Java给Excel文档设置内置文档属性和自定义文档属性。Jar包导入:
方法一:下载Free Spire.XLS for Java包并解压缩,将lib文件夹下的Spire.Xls.jar包作为依赖项导入到Java应用程序中。
方法二:直接通过Maven仓库安装JAR包,配置pom.xml文件的代码如下
<repositories>
<repository>
<id>com.e-iceblue</id>
<url>http://repo.e-iceblue.cn/repository/maven-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("Input.xlsx");
//给文档设置标题、主题、作者等内置文档属性
workbook.getDocumentProperties().setTitle("设置文档属性");
workbook.getDocumentProperties().setSubject("进货单");
workbook.getDocumentProperties().setAuthor("张丽");
workbook.getDocumentProperties().setManager("王刚");
workbook.getDocumentProperties().setCompany("**公司");
workbook.getDocumentProperties().setCategory("支出");
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("编辑", "王晓丽");
workbook.getCustomDocumentProperties().add("联系电话", 81705109);
workbook.getCustomDocumentProperties().add("更新日期", new Date());
//保存结果文档
workbook.saveToFile("CustomDocumentProperties.xlsx", ExcelVersion.Version2013);
}
}
标签:author input epo xls rop document 结果 strong rom
原文地址:https://blog.51cto.com/14765544/2507723