Spire.Cloud.PowerPoint 添加、删除 PowerPoint 文档属性

 

Spire.Cloud.PowerPoint 为开发人员提供了PropertiesApi接口,可用于添加和删除PPT文档属性。本文将介绍如何使用该接口来实现上述操作。

详细步骤如下:

步骤1、创建一个Maven程序,通过Maven仓库安装Spire.Cloud.SDK jar包及依赖,详细步骤可参考这篇文章

步骤2、通过冰蓝云官网(https://cloud.e-iceblue.cn/)注册账号并登陆,在“我的应用”版块创建应用程序,获得App ID及App Key。

步骤3、上传PowerPoint文档至冰蓝云官网的“文档管理”版块。为了便于文档管理,您也可以先创建文件夹“input”和“output”,然后将需要编辑的PowerPoint文档上传至input文件夹下,output文件夹用于存放生成的文档。

Spire.Cloud.PowerPoint 添加、删除 PowerPoint 文档属性

步骤4、在Java程序中编写代码来添加和删除PowerPoint文档属性。

示例1、添加文档属性

import spire.cloud.powerpoint.sdk.*;
import spire.cloud.powerpoint.sdk.api.PropertiesApi;
import spire.cloud.powerpoint.sdk.model.*;

public class setPptDocumentProperties {
    static String appId = " APP ID ";
    static String appKey = " APP Key ";
    static String baseUrl = "https://api.e-iceblue.cn";
    //配置APP ID和APP Key
    static Configuration configuration = new Configuration(appId, appKey, baseUrl);
    //创建propertiesApi实例
    static PropertiesApi propertiesApi = new PropertiesApi(configuration);

    public static void main(String[] args) throws ApiException {
        //示例文档名称
        String name = "sample.pptx";
        //示例文档的密码
        String password = null;
        //存放示例文档的文件夹
        String folder = "input";
        //使用冰蓝云默认的存储空间
        String storage = null;

        //设置PowerPoint文档属性,并将其添加到List
        java.util.ArrayList propertyList = new java.util.ArrayList();
        DocumentProperty property1 = new DocumentProperty();
        property1.setName("Keywords");
        property1.setValue("Set document properties.");
        property1.setBuiltIn(false);
        propertyList.add(property1);
        DocumentProperty property2 = new DocumentProperty();
        property2.setName("Author");
        property2.setValue("e-iceblue");
        property2.setBuiltIn(false);
        propertyList.add(property2);
        DocumentProperty property3 = new DocumentProperty();
        property3.setName("Company");
        property3.setValue("iceblue");
        property3.setBuiltIn(false);
        propertyList.add(property3);
        DocumentProperty property4 = new DocumentProperty();
        property4.setName("Title");
        property4.setValue("Test Document");
        property4.setBuiltIn(false);
        propertyList.add(property4);
        DocumentProperty property5 = new DocumentProperty();
        property5.setName("Subject");
        property5.setValue("Set properties");
        property5.setBuiltIn(false);
        propertyList.add(property5);
        DocumentProperties properties = new DocumentProperties();
        properties.list(propertyList);

        //调用setPptDocumentProperties设置文档属性
        propertiesApi.setPptDocumentProperties(name, properties, password, folder, storage);
    }
}

Spire.Cloud.PowerPoint 添加、删除 PowerPoint 文档属性

示例2、删除PPT文档属性

import spire.cloud.powerpoint.sdk.*;
import spire.cloud.powerpoint.sdk.api.PropertiesApi;
import spire.cloud.powerpoint.sdk.model.*;

public class deletePptDocumentProperties {
    static String appId = " APP ID ";
    static String appKey = " APP Key ";
    static String baseUrl = "https://api.e-iceblue.cn";
    //配置APP ID和APP Key
    static Configuration configuration = new Configuration(appId, appKey, baseUrl);
    //创建propertiesApi实例
    static PropertiesApi propertiesApi = new PropertiesApi(configuration);

    public static void main(String[] args) throws ApiException {
        //示例文档名称
        String name = "sample.pptx";
        //示例文档的密码
        String password = null;
        //存放示例文档的文件夹
        String folder = "input";
        //使用冰蓝云默认的存储空间
        String storage = null;

        //调用deletePptDocumentProperties删除文档属性
        propertiesApi.deletePptDocumentProperties(name, password, folder, storage);
    }
}

Spire.Cloud.PowerPoint 添加、删除 PowerPoint 文档属性