Telerik blogs
how-tot2-dark_1200x303

Check out this blog post to get an overview of the Notes functionality in SpreadProcessing.

One of the new additions to the SpreadProcessing library is support for Notes. Notes help you annotate the data inside cells or make it clearer by including additional information for the cell content. The SpreadProcessing API enables you to iterate all notes in a document, modify them or create new ones.

No matter whether you need to add, delete or modify a note, all the SpreadsheetNote objects can be accessed through the Notes collection of your Worksheet. The collection exposes simple methods to add or remove a note as well as an indexer, enabling you to iterate all the notes that are currently inside the document.

The code in the next snippet shows how you can open an XLSX document and delete all notes in the first Worksheet:

Workbook workbook;
using (Stream str = File.OpenRead(sampleFilePath))
{
    XlsxFormatProvider provider = new XlsxFormatProvider();
    workbook = provider.Import(str);
}
 
workbook.Worksheets[0].Notes.Clear();

OK. That was pretty easy, but what about creating a note or modifying an existing one? Don’t worry—it is simple as well. 

All that you need to specify when inserting a new note is the cell the note refers to and the position of the note. Let’s create a simple spreadsheet document to demonstrate that.

// Create document
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets.Add();
 
CellIndex a1Index = new CellIndex(0, 0);
worksheet.Cells[a1Index].SetValue("Example here");
worksheet.Cells[a1Index].SetIsWrapped(true);
 
// Create and add a note
// The index of the cell the note is associated to. (A1 in this case)
CellIndex relatedCellIndex = a1Index;
// The index of the cell the note will be visualized on when all notes are shown. (C3 in this case)
CellIndex cellIndex = new CellIndex(2, 2);
string author = "John Doe";
string text = "My First Comment Content";
 
worksheet.Notes.Add(relatedCellIndex, cellIndex, author, text);
 
// Save document
using (Stream stream = File.OpenWrite("InsertNote.xlsx"))
{
    XlsxFormatProvider provider = new XlsxFormatProvider();
    provider.Export(workbook, stream);
}

Once you open the file generated by the above code, you will see the little red triangle in the top right corner of the cell indicating that there is a note on that cell. Hovering the cell will show you the note we have just inserted:

Notes in spreadsheet produced by SpreadProcessing

If you would like, you can also show the comments inside your worksheet—this ensures that they are always visible, and the users don’t need to hover on a cell to see them on their arranged positions.

The next snippet and image show how to set the notes to be visible and how that will look in the document:

worksheet.Notes.ShowAll();

Show all Notes

As you can see from the image, the note is positioned on the index we have initially applied to it.

The SpreadProcessing API exposes different possibilities for manipulating or deleting existing notes as well as adding new ones. You can change the note content, position, size, visibility and more. If you are curious to explore all of them, head out to the documentation page for this feature: SpreadProcessing | Notes topic.

Try It and Share Your Feedback 

No matter if you are already familiar with Telerik Document Processing or will meet the libraries for the first time, hurry up and get the latest bits so you can take advantage of the different document management possibilities they provide:

Download a Free Trial

And I am sure I have told you many times that your input is valuable. We do listen. So, do not be shy and drop us a line to share your feedback in the comments section below or directly in our Document Processing Libraries Feedback Portal


Tanya-Dimitrova
About the Author

Tanya Dimitrova

Tanya Dimitrova is a Tech Support Engineer in the Telerik XAML Team. In her work her main responsibility is to assist clients to implement different scenarios using the document processing libraries and editors. She is passionate in finding new adventures and in her free time enjoys travelling, reading, swimming, dancing or just spending time with friends.

Related Posts

Comments

Comments are disabled in preview mode.