This article will demonstrate how to set and delete Excel document properties with the PropertiesApi interface provided by Spire.Cloud.Excel API.
Set Document Properties
import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.PropertiesApi;
import spire.cloud.excel.sdk.model.DocumentProperties;
import spire.cloud.excel.sdk.model.DocumentProperty;
import java.util.ArrayList;
public class SetDocumenmtProperties {
static String appId = "APP ID";
static String appKey = "APP Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration object based on App ID, App Key and base Url
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create an instance of PropertiesApi
static PropertiesApi propertiesApi = new PropertiesApi(configuration);
public static void main(String[] args) throws ApiException {
//Specify the name of the input Excel document
String name = "test.xlsx";
//Create an object of DocumentProperties
DocumentProperties properties = new DocumentProperties();
//Set the document properties
DocumentProperty property1 = new DocumentProperty("Title", "Test Document", true);
DocumentProperty property2 = new DocumentProperty("Subject", "Set Documenmt Properties", true);
DocumentProperty property3 = new DocumentProperty("Keywords", "Excel, Properties", true);
DocumentProperty property4 = new DocumentProperty("Category", "Tutorial", true);
DocumentProperty property5 = new DocumentProperty("Comments", "An important document.", true);
DocumentProperty property6 = new DocumentProperty("Author", "Spire.Cloud.SDK", true);
DocumentProperty property7 = new DocumentProperty("Company", "E-iceble Cloud", true);
properties.setList(new ArrayList());
properties.getList().add(property1);
properties.getList().add(property2);
properties.getList().add(property3);
properties.getList().add(property4);
properties.getList().add(property5);
properties.getList().add(property6);
properties.getList().add(property7);
//Specify the original password of the input document, set it to null if there's none
String password = null;
//Specify the folder where the input document is stored, set it to null if there's none
String folder = "input";
//Store the generated document in the 2G default storage space offered by E-iceblue Cloud
String storage = null;
//Set document properties for the Excel document with the "setDocumentProperties" method
propertiesApi.setDocumentProperties(name, properties, password, folder, storage);
}
}
Delete Specific Document Property
import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.PropertiesApi;
public class DeleteSpecificProperty {
static String appId = "App ID";
static String appKey = "APP Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration object based on App ID, App Key and base Url
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create an instance of PropertiesApi
static PropertiesApi propertiesApi = new PropertiesApi(configuration);
public static void main(String[] args) throws ApiException {
//Specify the name of the input Excel document
String name = "test.xlsx";
//Specify the specific document property that needed to be deleted
String propertyName = "Title";
//Specify the original password of the input document, set it to null if there's none
String password = null;
//Specify the folder where the input document is stored, set it to null if there's none
String folder = "input";
//Store the generated document in the 2G default storage space offered by E-iceblue Cloud
String storage = null;
//Delete the specific document property with "deleteDocumentProperty" method
propertiesApi.deleteDocumentProperty(name, propertyName, password, folder, storage);
}
}
Delete All Document Properties
import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.PropertiesApi;
public class DeleteProperties {
static String appId = "APP ID";
static String appKey = "APP Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration object based on App ID, App Key and base Url
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create an instance of PropertiesApi
static PropertiesApi propertiesApi = new PropertiesApi(configuration);
public static void main(String[] args) throws ApiException {
//Specify the name of the input Excel document
String name = "test.xlsx";
//Specify the original password of the input document, set it to null if there's none
String password = null;
//Specify the folder where the input document is stored, set it to null if there's none
String folder = "input";
//Store the generated document in the 2G default storage space offered by E-iceblue Cloud
String storage = null;
//Delete all document properties with "deleteDocumentProperties" method
propertiesApi.deleteDocumentProperties(name, password, folder, storage);
}
}