ComponentOne Excel for .NET
In This Topic
    Adding a Comment to a Cell
    In This Topic

    To add a comment to a cell, complete the following steps:

    1. Double-click the C1XLBook component in the Toolbox to add it to your form.
    2. Add text to a cell in the worksheet using the following code:

      To write code in Visual Basic

      Visual Basic
      Copy Code

      C1XLBook1.Sheets(0)(2, 3).Value = "test"

      To write code in C#

      C#
      Copy Code

      c1XLBook1.Sheets[0][2, 3].Value = "test";

    3. Add a comment to the XLCommentCollection and create a box to show it in using the following code:

      To write code in Visual Basic

      Visual Basic
      Copy Code

      C1XLBook1.Sheets(0).Comments.Add(2, 3, "John", "Test comment")
      C1XLBook1.Sheets(0).Comments(0).TextBox.Rectangle = New Rectangle(220, 210, 1900, 1200)

      To write code in C#

      C#
      Copy Code

      c1XLBook1.Sheets[0].Comments.Add(2, 3, "John", "Test comment");
      c1XLBook1.Sheets[0].Comments[0].TextBox.Rectangle = new Rectangle(220, 210, 1900, 1200);

    4. Save and open the book:

      To write code in Visual Basic

      Visual Basic
      Copy Code

      C1XLBook1.Save("c:\mybook.xls")
      System.Diagnostics.Process.Start("C:\mybook.xls")

      To write code in C#

      C#
      Copy Code

      c1XLBook1.Save(@"c:\mybook.xls");
      System.Diagnostics.Process.Start(@"C:\mybook.xls");

    5. Run the program. The spreadsheet will open and look similar to the following: