Java 添加、读取、删除PPT文档属性

文档属性是一些描述性的信息,它未包含在文件的实际内容中,提供有关文件的信息,可用来帮助查找和整理文件。以下示例中将介绍通过Java程序来添加PPT文档属性、读取、删除PPT文档中已有属性的方法。

 

使用工具:Free Spire.Presentation for Java(免费版)

Jar文件获取及导入:

方法1下载jar文件包。解压文件后,将lib文件夹下的Spire.Presentation.jar文件导入Java程序。

方法2可通过maven仓库导入到程序。

 

Java代码示例

【示例1】添加PPT文档属性

import com.spire.presentation.*;
import java.sql.Date;
import java.time.LocalDate;

public class AddProperty {
    public static void main(String[]args) throws Exception {
        //加载测试文档
        Presentation ppt = new Presentation();
        ppt.loadFromFile("test.pptx");

        //添加文档属性
        ppt.getDocumentProperty().setAuthor("Sam");
        ppt.getDocumentProperty().setManager("Danny");
        ppt.getDocumentProperty().setCategory("B类");
        ppt.getDocumentProperty().setCompany("E-iceblue");
        ppt.getDocumentProperty().setKeywords("测试,文档,内部文档");
        ppt.getDocumentProperty().setComments("仅供内部使用");
        ppt.getDocumentProperty().setLastSavedBy("Jamy");
        ppt.getDocumentProperty().setSubject("经贸");
        ppt.getDocumentProperty().setContentStatus("可编辑");
        ppt.getDocumentProperty().setLastSavedTime(new java.util.Date());

        //保存
        ppt.saveToFile("addproperty.pptx",FileFormat.PPTX_2010);
        ppt.dispose();
    }
}

文档属性添加效果:

 

【示例2】读取PPT文档属性

import com.spire.presentation.*;

public class GetProperty {
    public static void main(String[]args) throws Exception{
        //加载文档
        Presentation ppt = new Presentation();
        ppt.loadFromFile("addproperty.pptx");

        //读取文档属性
        System.out.println("标题: " + ppt.getDocumentProperty().getTitle());
        System.out.println("主题: " + ppt.getDocumentProperty().getSubject());
        System.out.println("作者: " + ppt.getDocumentProperty().getAuthor());
        System.out.println("单位: " + ppt.getDocumentProperty().getCompany());
        System.out.println("主管: " + ppt.getDocumentProperty().getManager());
        System.out.println("类别: " + ppt.getDocumentProperty().getCategory());
        System.out.println("关键字:" + ppt.getDocumentProperty().getKeywords());
        System.out.println("备注: " + ppt.getDocumentProperty().getComments());
        System.out.println("内容状态:"+ ppt.getDocumentProperty().getContentStatus());
    }
}

文档属性读取效果:

 

【示例3】删除PPT文档属性

import com.spire.presentation.*;

public class RemoveProperty {
    public static void main(String[] args ) throws Exception{
        //加载文档
        Presentation ppt = new Presentation();
        ppt.loadFromFile("addproperty.pptx");

        //通过将对应文档属性的值设置为空来删除文档属性
        ppt.getDocumentProperty().setTitle("");
        ppt.getDocumentProperty().setManager("");
        ppt.getDocumentProperty().setCategory("");
        ppt.getDocumentProperty().setCompany("");
        ppt.getDocumentProperty().setKeywords("");
        ppt.getDocumentProperty().setComments("");
        ppt.getDocumentProperty().setLastSavedBy("");
        ppt.getDocumentProperty().setSubject("");
        ppt.getDocumentProperty().setContentStatus("");

        //保存
        ppt.saveToFile("RemoveProperty.pptx",FileFormat.PPTX_2013);
        ppt.dispose();
    }
}

运行程序后,文档属性被删除。

(本文完)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值