Workbook 接口描述

 

操作Excel文档,包括新建Excel文档,读取文档信息,将文档转换为其他格式,加密/解密文档及保护/取消保护文档。

接口方法1: createWorkbook()新建Excel文档

HTTP 请求方法:POST

请求URL:https://api.e-iceblue.cn/v1/excel/{name}/workbook

请求参数:

参数 是否必选 类型 可选值范围 说明
name string   结果文档的名称
data file   可上传带有数据源的模板文档
inputPassword string   输入文档的密码,没有则null
password string   文档密码,没有则为null
folder string   存放结果文档的文件夹,没有则为null
storage string   文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null

Java代码示例:

import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.WorkbookApi;
import spire.cloud.excel.sdk.model.Workbook;
import java.io.File;

public class CreateWorkbook {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration configuration = new Configuration(appId, appKey, baseUrl);
    static WorkbookApi workbookApi = new WorkbookApi(configuration);

    public static void main(String[] args) throws ApiException {
        
String name = "CreateWorkbook.xlsx";
        String filePath = "data/Sample.xlsx";
        File data=new File(filePath);
        String inputPassword = null;
        String password = null;
        String storage = null;
        String folder = "output";
        Workbook response = workbookApi.createWorkbook(name, data, inputPassword, password, storage, folder);
    }
}

接口方法2:createWorkbookFromSource()基于现有数据源创建Excel文档

HTTP 请求方法:POST

请求URL:https://api.e-iceblue.cn/v1/excel/{name}/fromSource

请求参数:

参数 是否必选 类型 可选值范围 说明
name string   模板文档名称
sourcePath string   存储模板文档的文件夹,没有则null
sourcePassword string   模板文档的密码,没有则null
sourceStorage string   模板文档存储空间,可设置为null
password string   结果文档密码,没有则为null
storage string   结果文档的存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null
folder string   存放结果文档的文件夹,没有则为null

Java代码示例:

import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.WorkbookApi;
import spire.cloud.excel.sdk.model.*;

public class createWorkbookFromSource {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration configuration = new Configuration(appId, appKey, baseUrl);
    static WorkbookApi workbookApi = new WorkbookApi(configuration);

    public static void main(String[] args) throws ApiException {
        String name = "FromSource.xlsx";
        String sourcePath = "input";
        String sourcePassword = null;
        String sourceStorage = null;
        String password = null;
        String storage = null;
        String folder = "output";
        Workbook response = workbookApi.createWorkbookFromSource(name, sourcePath, sourcePassword, sourceStorage, password, storage, folder);
    }
}

接口方法3:GetWorkbook()获取Excel文档的数据信息

HTTP 请求方法:GET

请求URL:https://api.e-iceblue.cn/v1/excel/{name}/workbook

请求参数:

参数 是否必选 类型 可选值范围 说明
name string   文档名称
password string   文档密码,没有则为null
storage string   文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null
folder string   存放文档的文件夹,没有则为null

Java代码示例:

import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.WorkbookApi;
import spire.cloud.excel.sdk.model.*;

public class getWorkbook {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration configuration = new Configuration(appId, appKey, baseUrl);
    static WorkbookApi workbookApi = new WorkbookApi(configuration);

    public static void main(String[] args) throws ApiException {

        String name = "GetWorkbook.xlsx";
        String password = null;
        String storage = null;
        String folder = "input";
        Workbook response = workbookApi.getWorkbook(name, password, storage, folder);
    }
}

接口方法4:ConvertWorkbook()将Excel文档转换成其他格式

HTTP 请求方法:POST

请求URL:https://api.e-iceblue.cn/v1/excel/{name}/convert/{format}

请求参数:

参数 是否必选 类型 可选值范围 说明
name string   原文档名称
format string   指定结果文档的格式,支持Xlsx, Xlsb, Xls, Ods, Pdf, Xps, Ps, Pcl
options object { "Format": "string" } 设置结果文档选项,默认为null
password string   原文档密码,没有则为null
storage string   文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null
folder string   存放原文档的文件夹,没有则为null

Java代码示例:

import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.WorkbookApi;
import spire.cloud.excel.sdk.model.*;
import java.io.File;

public class convertWorkbook {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration configuration = new Configuration(appId, appKey, baseUrl);
    static WorkbookApi workbookApi = new WorkbookApi(configuration);

    public static void main(String[] args) throws ApiException {

        String name = "ConvertWorkbook.xlsx";
        String format = ExportFormat.XLSX.toString();//Supported formats: XLSX/XLS/XLSB/ODS/PDF/XPS/PS/PCL
        ExportOptions options = null;
        String password = null;
        String storage = null;
        String folder = "input";
        File response = workbookApi.convertWorkbook(name, format, options, password, storage, folder);
    }
}

接口方法5:convertWorkbookToPath()将Excel文档保存为指定的文档格式

HTTP 请求方法:PUT

请求URL:https://api.e-iceblue.cn/v1/excel /{name}/convert/{format}

请求参数:

参数 是否必选 类型 可选值范围 说明
name string   原文档名称
destFilePath string   结果文档的存贮路径,如果省略该参数,则默认存到根目录
format string   设置结果文档格式,支持Xlsx, Xlsb, Xls, Ods, Pdf, Xps, Ps, Pcl
options object { "Format": "string" } 结果文档选项,默认null
password string   原文档密码,没有则为null
storage string   文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null
folder string   存放原文档的文件夹,没有则为null

Java代码示例:

import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.WorkbookApi;
import spire.cloud.excel.sdk.model.*;

public class convertWorkbookToPath {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration configuration = new Configuration(appId, appKey, baseUrl);
    static WorkbookApi workbookApi = new WorkbookApi(configuration);

    public static void main(String[] args) throws ApiException {
       
        String name = "ConvertWorkbookToPath.xlsx";
        String outPath = "output/ConvertWorkbookToPath.xlsx";
        String format = ExportFormat.XLSX.toString();//Supported formats: XLSX/XLS/XLSB/ODS/PDF/XPS/PS/PCL
        ExportOptions options = null;
        String password = null;
        String storage = null;
        String folder = "input";
        workbookApi.convertWorkbookToPath(name, outPath, format, options, password, storage, folder);
    }
}

接口方法6:encryptDocument()加密Excel文档

HTTP 请求方法:POST

请求URL:https://api.e-iceblue.cn/v1/excel /{name}/encryption

请求参数:

参数 是否必选 类型 可选值范围 说明
name string   文档名称
encryption object { "EncryptionType": "EncryptionType", "KeyLength": 0, "Password": "Password" } 为文档设置打开密码
folder string   存放文档的文件夹,没有则为null
storage string   文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null

Java代码示例:

import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.WorkbookApi;
import spire.cloud.excel.sdk.model.*;

public class encryptDocument {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration configuration = new Configuration(appId, appKey, baseUrl);
    static WorkbookApi workbookApi = new WorkbookApi(configuration);

    public static void main(String[] args) throws ApiException {

        String name = "EncryptDocument.xlsx";
        String storage = null;
        String folder = "input";
        WorkbookEncryptionRequest encryption = new WorkbookEncryptionRequest();
        encryption.password("123");
        workbookApi.encryptDocument(name, encryption, folder, storage);
    }
}

接口方法7:decryptDocument()解密Excel文档

HTTP 请求方法:DELETE

请求URL:https://api.e-iceblue.cn/v1/excel /{name}/encryption

请求参数:

参数 是否必选 类型 可选值范围 说明
name string   原文档名称
encryption object { "EncryptionType": "EncryptionType", "KeyLength": 0, "Password": "Password" } 指定原文档的打开密码,并解密设置
folder string   存放原文档的文件夹,没有则为null
storage string   文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null

Java代码示例:

import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.WorkbookApi;
import spire.cloud.excel.sdk.model.*;

public class decryptDocument {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration configuration = new Configuration(appId, appKey, baseUrl);
    static WorkbookApi workbookApi = new WorkbookApi(configuration);

    public static void main(String[] args) throws ApiException {

        String storage = null;
        String folder = "input";
        String name = "DecryptDocument.xlsx";
        WorkbookEncryptionRequest encryption = new WorkbookEncryptionRequest();
        encryption.password("123");
        workbookApi.decryptDocument(name, encryption, folder, storage);
    }
}

接口方法8:protectDocument()保护Excel工作簿

HTTP 请求方法:POST

请求URL:https://api.e-iceblue.cn/v1/excel /{name}/protection

请求参数:

参数 是否必选 类型 可选值范围 说明
name string   原文档名称
protection object { "ProtectionType": "ProtectionType", "Password": "Password" } 设置文档保护密码和保护方式
folder string   存放原文档的文件夹,没有则为null
storage string   文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null

Java代码示例:

import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.WorkbookApi;
import spire.cloud.excel.sdk.model.*;

public class protectDocument {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration configuration = new Configuration(appId, appKey, baseUrl);
    static WorkbookApi workbookApi = new WorkbookApi(configuration);

    public static void main(String[] args) throws ApiException {

        String name = "ProtectDocument.xlsx";
        String folder = "input";
        String storage = null;
        WorkbookProtectionRequest protection = new WorkbookProtectionRequest();
        protection.password("123");
        protection.protectionType("ALL");//Available value: ALL, READONLY, STRUCTURE, WINDOWS
        workbookApi.protectDocument(name, protection, folder, storage);
    }
}

接口方法9:unProtectDocument()取消保护Excel工作簿

HTTP 请求方法:DELETE

请求URL:https://api.e-iceblue.cn/v1/excel /{name}/protection

请求参数:

参数 是否必选 类型 可选值范围 说明
name string   原文档名称
protection object { "ProtectionType": "ProtectionType", "Password": "Password" } 指定文档的保护密码和保护方式
folder string   存放原文档的文件夹,没有则为null
storage string   文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null

Java代码示例:

import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.WorkbookApi;
import spire.cloud.excel.sdk.model.*;

public class unProtectDocument {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration configuration = new Configuration(appId, appKey, baseUrl);
    static WorkbookApi workbookApi = new WorkbookApi(configuration);

    public static void main(String[] args) throws ApiException {

        String name = "UnProtectDocument.xlsx";
        String folder = "input";
        String storage = null;
        WorkbookProtectionRequest protection = new WorkbookProtectionRequest();
        protection.password("123");
        protection.protectionType("READONLY");//Available value: ALL, READONLY, STRUCTURE, WINDOWS
        workbookApi.unProtectDocument(name, protection, folder, storage);
    }
}