当前位置: 移动技术网 > IT编程>开发语言>Java > Java 添加、读取、删除PPT文档属性

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

2019年07月09日  | 移动技术网IT编程  | 我要评论

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

 

使用工具:free spire.presentation for java(免费版)

jar文件获取及导入:

方法1下载jar文件包。解压文件后,将lib文件夹下的spire.presentation.jar文件导入java程序。

方法2可通过到程序。

 

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();
    }
}

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

 

(本文完)

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网