Java添加、读取、删除Excel文档属性的方法是什么
发表于:2024-10-17 作者:千家信息网编辑
千家信息网最后更新 2024年10月17日,本篇内容介绍了"Java添加、读取、删除Excel文档属性的方法是什么"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读
千家信息网最后更新 2024年10月17日Java添加、读取、删除Excel文档属性的方法是什么
本篇内容介绍了"Java添加、读取、删除Excel文档属性的方法是什么"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
使用工具:Spire.XLS for Java
获取方法:通过官网下载包。下载后,解压文件,并将lib文件夹下的jar文件导入java程序;或者通过Maven仓库下载导入。Jar导入效果如下:
Java 代码示例
【示例1】添加Excel文档属性
import com.spire.xls.*; import java.util.Date; public class AddProperties { public static void main(String[] args) { //加载Excel文档 Workbook wb = new Workbook(); wb.loadFromFile("input.xlsx"); //给文档设置标题、主题、作者等内置文档属性 wb.getDocumentProperties().setTitle("设置文档属性"); wb.getDocumentProperties().setSubject("A类"); wb.getDocumentProperties().setAuthor("Bubble"); wb.getDocumentProperties().setManager("July"); wb.getDocumentProperties().setCompany("Alibaba"); wb.getDocumentProperties().setCategory("内部"); wb.getDocumentProperties().setKeywords("文档、草稿"); //给文档添加自定义文档属性 wb.getCustomDocumentProperties().add("_MarkAsFinal", true); wb.getCustomDocumentProperties().add("编辑", "Administrator"); wb.getCustomDocumentProperties().add("联系电话", 12345678); wb.getCustomDocumentProperties().add("更新日期", new Date()); //保存结果文档 wb.saveToFile("AddProperties.xlsx", ExcelVersion.Version2010); wb.dispose(); } }
生成的文档可查看属性添加效果。
【示例2】读取Excel文档属性
import com.spire.xls.*; public class ReadProperties { public static void main(String[] args) { //加载Excel文档 Workbook wb = new Workbook(); wb.loadFromFile("AddProperties.xlsx"); //获取Excel内置文档属性 System.out.println("标题: " + wb.getDocumentProperties().getTitle()); System.out.println("主题: " + wb.getDocumentProperties().getSubject()); System.out.println("作者: " + wb.getDocumentProperties().getAuthor()); System.out.println("单位: " + wb.getDocumentProperties().getCompany()); System.out.println("主管: " + wb.getDocumentProperties().getManager()); System.out.println("类别: " + wb.getDocumentProperties().getCategory()); System.out.println("关键字: " + wb.getDocumentProperties().getKeywords()); //获取Excel自定义文档属性 DocumentProperty property = (DocumentProperty) wb.getCustomDocumentProperties().get(0); //读取第一个自定义文档属性的名称和值 System.out.println("名称: " + property.getName()); System.out.println("值: " + property.getValue()); } }
文档属性读取结果:
【示例3】删除Excel文档属性
import com.spire.xls.*; public class RemoveProperties { public static void main(String[] args) { //加载Excel文档 Workbook wb = new Workbook(); wb.loadFromFile("AddProperties.xlsx"); //通过将对应文档属性的值设置为空来删除该内置属性 wb.getDocumentProperties().setTitle(""); wb.getDocumentProperties().setSubject(""); wb.getDocumentProperties().setAuthor(""); wb.getDocumentProperties().setCompany(""); wb.getDocumentProperties().setManager(""); wb.getDocumentProperties().setCategory(""); wb.getDocumentProperties().setKeywords(""); wb.getDocumentProperties().setComments(""); //根据自定义文档属性的名称来移除该自定义文档属性 wb.getCustomDocumentProperties().remove("编辑"); wb.getCustomDocumentProperties().remove("联系电话"); //保存文档 wb.saveToFile("RemoveProperties.xlsx", ExcelVersion.Version2010); wb.dispose(); } }
生成的文档可查看属性删除效果。
"Java添加、读取、删除Excel文档属性的方法是什么"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
文档
属性
示例
方法
名称
效果
文件
主题
作者
内容
更多
标题
电话
知识
结果
联系电话
生成
联系
实用
学有所成
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
帮有网络技术有限公司怎么样
丈八网络安全公司
杭州远程视频系统服务器
什么是数据库透明加密
工控网络安全数据集
网页数据库录入
pg删除数据库
scum不要服务器怎么联机
数据库有ip地址吗
实例讲解软件开发项目管理
浪潮软件开发工资待遇
wuauclt 数据库引擎
大话2怎么查可移民服务器
大兴区品牌软件开发介绍
服务器硬件安装培训
车站服务器的管理卡
网络安全前沿进展
只能重启服务器
数据库小数点设置
列出一列的重复数据库
我要安全安培网络安全
爱达普网络技术
美萍数据库损坏
网易云音乐数据库表结构
辽宁信息化软件开发服务五星服务
花生壳搭建服务器
攀枝花学院管网络安全张靖
中国互联网科技发达吗
公安局召开网络安全会议
不同公司合作如何规避网络安全