Spire.Cloud.Excel provides the WorksheetsApi interface to process the specific worksheet in an Excel document. This article shows you how to add or delete comments in worksheets by using this API.
Example 1. Add comment
using System;
using Spire.Cloud.Excel.Sdk.Api;
using Spire.Cloud.Excel.Sdk.Client;
using Spire.Cloud.Excel.Sdk.Model;
namespace AddComment
{
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 WorksheetsApi object
static WorksheetsApi WorksheetsApi = new WorksheetsApi(configuration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample.xlsx";
//Specify the folder where the source document is stored
string folder = "input";
//Use the default storage, set to null
string storage = null;
//Specify the worksheet name
string sheetName = "vendors";
//Specify the cell to which the comment will be added
string cellName = "C5";
//Create a Comment object
Comment comment = new Comment();
//Set the comment content
comment.Note = "This is a comment created by Spire.Cloud.Excel";
//Set it to visible
comment.IsVisible = true;
//Call AddComment method to add comment to the specific cell
WorksheetsApi.AddComment(name, sheetName, cellName, comment, folder, storage);
}
}
}
Example 2. Delete comment
using System;
using Spire.Cloud.Excel.Sdk.Api;
using Spire.Cloud.Excel.Sdk.Client;
namespace DeleteComment
{
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 WorksheetsApi object
static WorksheetsApi WorksheetsApi = new WorksheetsApi(configuration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample.xlsx";
//Specify the folder where the source document is stored
string folder = "input";
//Use the default storage, set to null
string storage = null;
//Specify the worksheet name
string sheetName = "vendors";
//Call DeleteComments method to delete all comments in the sheet
WorksheetsApi.DeleteComments(name, sheetName, folder, storage);
}
}
}