Excel cell comments

Following example demonstrates how to set Excel cell comment with location, text and visibility.

Sample also shows how to format individual characters and words within a comment text.

Comments reading/writing is supported in XLSX, XLS and ODS file formats.

Comments formatting is supported only in XLSX.

Screenshot of Excel cell comments set with GemBox.Spreadsheet for Java
Excel cell comments set with GemBox.Spreadsheet for Java
import com.gembox.spreadsheet.*;

class Program {

    public static void main(String[] args) throws java.io.IOException {
        // If using Professional version, put your serial key below.

        ExcelFile workbook = new ExcelFile();
        ExcelWorksheet worksheet = workbook.addWorksheet("Comments");

        worksheet.getCell(0, 0).setValue("Comment examples:");

        worksheet.getCell(2, 1).getComment().setText("Empty cell.");

        worksheet.getCell(4, 1).setValue(5);
        worksheet.getCell(4, 1).getComment().setText("Cell with a number.");

        worksheet.getCell("B7").setValue("Cell B7");

        ExcelComment comment = worksheet.getCell("B7").getComment();
        comment.setText("Some formatted text.\nComment is:\na) multiline,\nb) large,\nc) visible, and \nd) formatted.");
        comment.setTopLeftCell(new AnchorCell(worksheet.getColumn(3), worksheet.getRow(4), true));
        comment.setBottomRightCell(new AnchorCell(worksheet.getColumn(5), worksheet.getRow(10), false));

        // Get first 20 characters of a string.
        FormattedCharacterRange characters = comment.getCharacters(0, 20);

        // Apply color, italic and size to selected characters.

        // Apply color to 'formatted' part of text.
        comment.getCharacters(5, 9).getFont().setColor(SpreadsheetColor.fromName(ColorName.RED));


Check next example or download examples from GitHub.