专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

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

文档属性添加效果:

77_1.png

【示例****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());
    }
}

文档属性读取效果:

77_2.png

【示例****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();
    }
}

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

(本文完)

文章永久链接:https://tech.souyunku.com/48231

未经允许不得转载:搜云库技术团队 » Java 添加、读取、删除PPT文档属性

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们