EasyXLS™ library allows you to export Excel files with comments on cell sheets and set comment properties such as text, comment size, font settings and foreground.
The component also allows reading comments from Excel files.
// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
// Get the table of data for the first worksheet
ExcelTable xlsFirstTable =
((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable();
// Add data in cells for report headerfor (int column=0; column<5; column++)
{
xlsFirstTable.easy_getCell(0, column).setValue("Column " + (column + 1));
// Add comment on header columns
xlsFirstTable.easy_getCell(0, column).setComment(
"This is column no " + (column + 1));
}
...
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel comments.xlsx");
' Create an instance of the class that exports Excel files, having two sheetsDim workbook As New ExcelDocument(2)
' Get the table of data for the first worksheetDim xlsFirstTab As ExcelWorksheet = workbook.easy_getSheetAt(0)
Dim xlsFirstTable = xlsFirstTab.easy_getExcelTable()
' Add data in cells for report headerFor column As Integer = 0 To 4
xlsFirstTable.easy_getCell(0, column).setValue("Column " & (column + 1))
' Add comment on header columns
xlsFirstTable.easy_getCell(0, column).setComment( _
"This is column no " & (column + 1))
Next
...
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel comments.xlsx")
C++// Create an instance of the class that exports Excel files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
// Create two sheets
workbook->easy_addWorksheet_2("First tab");
workbook->easy_addWorksheet_2("Second tab");
// Get the table of data for the first worksheet
EasyXLS::IExcelWorksheetPtr xlsFirstTab =
(EasyXLS::IExcelWorksheetPtr)workbook->easy_getSheetAt(0);
EasyXLS::IExcelTablePtr xlsFirstTable = xlsFirstTab->easy_getExcelTable();
// Add data in cells for report headerchar* cellValue = (char*)malloc(11*sizeof(char));
char* columnNumber = (char*)malloc(sizeof(char));
char* commentValue = (char*)malloc(20*sizeof(char));
for (int column=0; column<5; column++)
{
strcpy(cellValue, "Column ");
_itoa(column+ 1, columnNumber , 10);
xlsFirstTable->easy_getCell(0,column)->setValue(
strcat(cellValue, columnNumber));
// Add comment on header columns
strcpy(commentValue, "This is column no ");
xlsFirstTable->easy_getCell(0, column)->setComment_2(
strcat(commentValue, columnNumber));
}
...
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel comments.xlsx");
Click here to see Continuous Code ListingC++.NET// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument ^workbook = gcnew ExcelDocument(2);
// Get the table of data for the first worksheet
ExcelWorksheet ^xlsFirstTab =
safe_cast<ExcelWorksheet^>(workbook->easy_getSheetAt(0));
ExcelTable ^xlsFirstTable = xlsFirstTab->easy_getExcelTable();
// Add data in cells for report headerfor (int column=0; column<5; column++)
{
xlsFirstTable->easy_getCell(0,column)->setValue(
String::Concat("Column ",(column + 1).ToString()));
// Add comment on header columns
xlsFirstTable->easy_getCell(0, column)->setComment(
String::Concat("This is column no ",(column + 1).ToString()));
}
...
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel comments.xlsx");
Click here to see Continuous Code Listing
// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
// Get the table of data for the first worksheet
ExcelTable xlsFirstTable =
((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable();
// Add data in cells for report headerfor (int column=0; column<5; column++)
{
xlsFirstTable.easy_getCell(0, column).setValue("Column " + (column + 1));
// Add comment on header columns
xlsFirstTable.easy_getCell(0, column).setComment(
"This is column no " + (column + 1));
}
...
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel comments.xlsx");
.NET:// Create an instance of the class that exports Excel files
$workbook = new COM("EasyXLS.ExcelDocument");
// Create two sheets
$workbook->easy_addWorksheet_2("First tab");
$workbook->easy_addWorksheet_2("Second tab");
// Get the table of data for the first worksheet
$xlsFirstTable = $workbook->easy_getSheetAt(0)->easy_getExcelTable();
// Add data in cells for report headerfor ($column=0; $column<5; $column++)
{
$xlsFirstTable->easy_getCell(0,$column)->setValue("Column " . ($column + 1));
// Add comment on header columns
$xlsFirstTable->easy_getCell(0, $column)->setComment_2(
"This is column no " . ($column + 1));
}
...
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel comments.xlsx");
Click here to see Continuous Code ListingJava:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Create two worksheets
$workbook->easy_addWorksheet("First tab");
$workbook->easy_addWorksheet("Second tab");
// Get the table of data for the first worksheet
$xlsFirstTable = $workbook->easy_getSheetAt(0)->easy_getExcelTable();
// Add data in cells for report headerfor ($column=0; $column<5; $column++)
{
$xlsFirstTable->easy_getCell(0,$column)->setValue("Column " . ($column + 1));
// Add comment for report header cells
$xlsFirstTable->easy_getCell(0, $column)->setComment("This is column no " . ($column + 1));
}
...
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel comments.xlsx");
Click here to see Continuous Code Listing
' Create an instance of the class that exports Excel filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Get the table of data for the first worksheetset xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
' Add data in cells for report headerfor column = 0 to 4
xlsFirstTable.easy_getCell(0, column).setValue("Column " & (column + 1))
' Add comment on header columns
xlsFirstTable.easy_getCell(0, column).setComment_2( _
"This is column no " & (column + 1))
next
...
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel comments.xlsx")
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Get the table of data for the first worksheetSet xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
' Add data in cells for report headerFor Column = 0 To 4
xlsFirstTable.easy_getCell(0, Column).setValue("Column " & (Column + 1))
' Add comment on header columns
xlsFirstTable.easy_getCell(0, Column).setComment_2( _
"This is column no " & (Column + 1))
Next
...
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel comments.xlsx")
' Create an instance of the class that exports Excel filesset workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Get the table of data for the first worksheetset xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
' Add data in cells for report headerfor column = 0 to 4
xlsFirstTable.easy_getCell(0, column).setValue("Column " & (column + 1))
' Add comment on header columns
xlsFirstTable.easy_getCell(0, column).setComment_2( _
"This is column no " & (column + 1))
next
...
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel comments.xlsx")
<!-- Create an instance of the class that exports Excel files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Create two sheets --><cfset ret = workbook.easy_addWorksheet("First tab")><cfset ret = workbook.easy_addWorksheet("Second tab")><!-- Get the table of data for the first worksheet --><cfset xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()><!-- Add data in cells for report header --><cfloop from = "0"to = "4"index = "column"><cfset xlsFirstTable.easy_getCell(0, evaluate(column)).setValue(
"Column " & evaluate(column + 1))><!-- Add comment on header columns --><cfset xlsFirstTable.easy_getCell(0, evaluate(column)).setComment(
"This is column no " & evaluate(column + 1))></cfloop>
...
<!-- Export Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Excel comments.xlsx")>
.NET:# Create an instance of the class that exports Excel files, having two sheets
workbook = ExcelDocument(2)
# Get the table of data for the first worksheet
xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
# Add data in cells for report headerfor column in range(5):
xlsFirstTable.easy_getCell(0, column).setValue("Column " + str(column + 1))
# Add comment for report header cells
xlsFirstTable.easy_getCell(0, column).setComment("This is column no " + str(column + 1))
...
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel comments.xlsx")
Click here to see Continuous Code ListingJava:# Create an instance of the class that exports Excel files, having two sheets
workbook = gateway.jvm.ExcelDocument(2)
# Get the table of data for the first worksheet
xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
# Add data in cells for report headerfor column in range(5):
xlsFirstTable.easy_getCell(0, column).setValue("Column " + str(column + 1))
# Add comment for report header cells
xlsFirstTable.easy_getCell(0, column).setComment("This is column no " + str(column + 1))
...
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel comments.xlsx")
Click here to see Continuous Code Listing
The screen shot provides an example of an Excel report that has comments added on first row. The comments are signaled out by the red right-upper corner on the cell. If you point your cursor on it, the comment box will be displayed.
Comment text
The comment text can be simple text as in the above code sample and set by using ExcelComment.setText method or it can be in rich text format. The RTF is attained by means of HTML syntax by using ExcelComment.setHTMLText method.
Comment font settings
EasyXLS allows you to set the font name, font size, bold and italic options, foreground, strikethrough, underline style, superscript and subscript by using methods from ExcelComment class.
For rich text formatting it is used the HTML syntax. The following tags are supported: <b> <strong> <i> <s> <strike> <sup> <sub> <font color= face= size=> The above tags have the same meaning as in HTML.
In order to set the underline style for a group of characters EasyXLS uses four specific tags: <u> <underline double> <underline single-accounting> <underline double-accounting>
Comment width and height
The width and height of the comment can be specified in pixels using DrawingObject.setSize method that is available in ExcelComment class because of the class inheritance.
Export comment to Excel file
EasyXLS allows you to export Excel files with comments using ExcelCell.setComment method. The above code sample shows how to achieve this goal.
EasyXLS allows you to read comments from Excel file using ExcelCell.getComment method. The Excel file must be imported first and after that the comments of the cells are available.