Spire.Cloud.Excel provides the PropertiesApi interface to handle properties of Excel documents. This article shows you how to add or remove properties by using this API.
Example 1. Set Document Properties
using System;
using System.Collections.Generic;
using Spire.Cloud.Excel.Sdk.Api;
using Spire.Cloud.Excel.Sdk.Client;
using Spire.Cloud.Excel.Sdk.Model;
namespace SetDocumentProperties
{
class Program
{
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 a PropertiesApi object
static PropertiesApi propertiesApi = new PropertiesApi(configuration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample.xlsx";
//Specify the open password of the source document, set to null if there’s no password
string password = null;
//Specify the folder where the source document is stored
string folder = "input";
//Use the default storage, set to null
string storage = null;
//Create a DocumentProperties object
DocumentProperties properties = new DocumentProperties();
//Set document properties
DocumentProperty property1 = new DocumentProperty("Title", "Sample", true);
DocumentProperty property2 = new DocumentProperty("Subject", "Document Properties", true);
DocumentProperty property3 = new DocumentProperty("Keywords", "Excel;Property", true);
DocumentProperty property4 = new DocumentProperty("Category", "Spire.Cloud Tutorials", true);
DocumentProperty property5 = new DocumentProperty("Comments", "None", true);
DocumentProperty property6 = new DocumentProperty("Author", "Spire.Cloud.SDK", true);
DocumentProperty property7 = new DocumentProperty("Company", "E-iceblue", true);
properties.List = new List();
properties.List.Add(property1);
properties.List.Add(property2);
properties.List.Add(property3);
properties.List.Add(property4);
properties.List.Add(property5);
properties.List.Add(property6);
properties.List.Add(property7);
//Call SetDocumentProperties to add properties to document
propertiesApi.SetDocumentProperties(name, properties, password, folder, storage);
}
}
}
Example 2. Remove Document Properties
using System;
using Spire.Cloud.Excel.Sdk.Api;
using Spire.Cloud.Excel.Sdk.Client;
namespace RemoveDocumentProperties
{
class Program
{
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 a PropertiesApi object
static PropertiesApi propertiesApi = new PropertiesApi(configuration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample.xlsx";
//Specify the open password of the source document, set to null if there’s no password
string password = null;
//Specify the folder where the source document is stored
string folder = "input";
//Use the default storage, set to null
string storage = null;
//Call DeleteDocumentProperties to remove all properties
propertiesApi.DeleteDocumentProperties(name, password, folder, storage);
}
}
}