Spire.Cloud.Excel provides the WorksheetsApi interface to manipulate worksheets in an Excel document. This article will demonstrate how to add a comment to an Excel worksheet and how to delete the existed comment.
Add a Comment to an Excel worksheet
import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.WorksheetsApi;
import spire.cloud.excel.sdk.model.*;
public class AddComment {
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.cloudxdocs.com";
public static void main(String[] args) throws ApiException {
//Create a configuration object based on your App ID and App Key
Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Initialize the WorksheetsApi object
WorksheetsApi WorksheetsApi = new WorksheetsApi(configuration);
//Load an Excel sample
String name = "Sample.xlsx";
//Specify the folder storing the sample, and it’s null if nothing
String folder =“input";
//Use the 2G storage provided by E-iceblue Cloud, and it’s null by default
String storage = null;
//Specify the first worksheet
String sheetName = "Country List";
//Specify the cell to be added a comment
String cellName = "B3";
//Add a comment to the specified cell
Comment comment = new Comment();
comment.setAuthor("Tina");//Specify the author of the comment
comment.setNote("Continent: South Asia");//Set the content of the comment
comment.setAutoSize(true);
comment.setTextOrientationType("crosswise");//Set the orientation of the text
comment.setTextVerticalAlignment("top");//Set the font alignment of the text
comment.setIsVisible(true);
//Call the addComment method to add a comment to the specific cell of the first worksheet
WorksheetsApi.addComment(name, sheetName, cellName, comment, folder, storage);
}
}
Output
Delete the existed comment in an Excel worksheet
import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.WorksheetsApi;
public class DeleteComment {
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.cloudxdocs.com";
public static void main(String[] args) throws ApiException {
//Create a configuration object based on your App ID and App Key
Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Initiate the WorksheetsApi object
WorksheetsApi WorksheetsApi = new WorksheetsApi(configuration);
//Load an Excel sample including a comment
String name = "Sample.xlsx";
//Specify the folder storing the sample, and it’s null if nothing
String folder ="input";
//Use the 2G storage provided by E-iceblue Cloud, and it’s null by default
String storage = null;
//Specify the first worksheet
String sheetName = "Country List";
//Call the deleteComments method to delete the existed comment in the worksheet
WorksheetsApi.deleteComments(name, sheetName, folder, storage);
}
}