资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Spire.Cloud.Word添加、获取和删除Word文档自定义属性-创新互联

前言:

创新互联公司专注于扬中企业网站建设,响应式网站,电子商务商城网站建设。扬中网站建设公司,为扬中等地区提供建站服务。全流程按需求定制设计,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务

Spire.Cloud 在线编辑器是一款基于网页的 Office 文件编辑工具,支持在网页中打开、编辑、打印 Word、Excel、PPT 文件,支持将文档保存到私有云盘。支持 IE、Chrome、FireFox、搜狗、遨游、360 等常见浏览器。Spire.Cloud Web API 能帮助开发人员能在任何时间、任何地点直接调用 SDK 接口对 Word、Excel、PPT、PDF 文档进行操作。Spire.Cloud 支持 .NET、Java、PHP、Python、JavaScript 等多种编程语言,并提供了 1 万次的免费调用次数及 2G 文档内存。

本文将通过实例阐述如何通过Spire.Cloud.Word API给开发人员提供的DocumentPropertiesApi接口,来添加、获取和删除Word文档自定义属性。

详细步骤:

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

Spire.Cloud.Word 添加、获取和删除 Word 文档自定义属性

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

Spire.Cloud.Word 添加、获取和删除 Word 文档自定义属性

3、创建Maven应用程序,通过Maven仓库安装Spire.Cloud.SDK jar包及依赖。详细步骤参考 文章 。


    
        com.e-iceblue
        cloud
        http://repo.e-iceblue.cn/repository/maven-public/
    


    
             cloud 
            spire.cloud.sdk
            3.5.0
        
    
        io.swagger
        swagger-annotations
        1.5.18
    
    
        com.squareup.okhttp
        okhttp
        2.7.5
    
    
        com.squareup.okhttp
        logging-interceptor
        2.7.5
    
    
         com.squareup.okio 
        okio
        1.6.0
    
    
        com.google.code.gson
        gson
        2.8.1
    
    
        io.gsonfire
        gson-fire
        1.8.0
    
    
        org.threeten
        threetenbp
        1.3.5
    

4、新建Java class,调用Spire.Cloud.Word API操作input文件夹下的示例文档。

示例1、添加自定义文档属性

import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.DocumentPropertiesApi;
import spire.cloud.word.sdk.client.model.*;
import java.util.ArrayList;
import java.util.List;
public class addCustomDocumentProperties {
    static String appId = " APP ID "; 
    static String appKey = " APP Key ";
    static String baseUrl = "https://api.e-iceblue.cn";
    //配置APP ID和APP Key
    static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
    //创建documentPropertiesApi实例
    static DocumentPropertiesApi documentPropertiesApi = new DocumentPropertiesApi(wordConfiguration);
    public static void main(String[] args) throws ApiException {
        //示例文档名称
        String name = "test.docx";
        //示例文档的密码
        String password = null;
        //存放示例文档的文件夹
        String folder = "input";
        //使用冰蓝云默认的存储空间
        String storage = null;
        //输出文档存放路径
        String destFilePath = "output/addCustomDocumentProperties_out.docx";
        //设置自定义文档属性
        List properties = new ArrayList();
        properties.add(new CustomDocumentProperty("Name1", "Value1"));
        properties.add(new CustomDocumentProperty("Name2", "Value2"));
        //调用addCustomDocumentProperties添加自定义文档属性
        documentPropertiesApi.addCustomDocumentProperties(name, properties, destFilePath, password, folder, storage);
    }
  }

Spire.Cloud.Word 添加、获取和删除 Word 文档自定义属性

示例2、获取自定义文档属性

import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.DocumentPropertiesApi;
import spire.cloud.word.sdk.client.model.*;
import java.util.List;
public class getCustomDocumentProperties {
    static String appId = " APP ID "; 
    static String appKey = " APP Key ";
    static String baseUrl = "https://api.e-iceblue.cn";
    //配置APP ID和APP Key
    static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
    //创建documentPropertiesApi实例
    static DocumentPropertiesApi documentPropertiesApi = new DocumentPropertiesApi(wordConfiguration);
    public static void main(String[] args) throws ApiException {
        //示例文档名称
        String name = "Sample.docx";
        //示例文档的密码
        String password = null;
        //存放示例文档的文件夹
        String folder = "input";
        //使用冰蓝云默认的存储空间
        String storage = null;
        //调用getCustomDocumentProperties读取自定义文档属性
        List response = documentPropertiesApi.getCustomDocumentProperties(name, password, folder, storage);
        System.out.println(response);
    }
  }

Spire.Cloud.Word 添加、获取和删除 Word 文档自定义属性

示例3、删除自定义文档属性

import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.DocumentPropertiesApi;
public class deleteCustomDocumentProperties {
    static String appId = " APP ID "; 
    static String appKey = " APP Key ";
    static String baseUrl = "https://api.e-iceblue.cn";
    //配置APP ID和APP Key
    static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
    //创建documentPropertiesApi实例
    static DocumentPropertiesApi documentPropertiesApi = new DocumentPropertiesApi(wordConfiguration);
    public static void main(String[] args) throws ApiException {
        //示例文档名称
        String name = "Sample.docx";
        //示例文档自定义属性中需要删除的项目
        String propertieName = "Owner";
        //示例文档的密码
        String password = null;
        //存放示例文档的文件夹
        String folder = "input";
        //使用冰蓝云默认的存储空间
        String storage = null;
        //输出文档存放路径
        String destFilePath = "output/deleteCustomDocumentProperties_output.docx";
        //调用deleteCustomDocumentProperty删除指定的自定义文档属性
        documentPropertiesApi.deleteCustomDocumentProperty(name, propertieName, destFilePath, password, folder, storage);
    }
  }

当前文章:Spire.Cloud.Word添加、获取和删除Word文档自定义属性-创新互联
URL地址:http://cdkjz.cn/article/dhegej.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220