Microsoft Excel provides the option to add comments in Excel files. There can be several reasons for adding comments, such as explaining a formula or adding contextual information that might be useful to the reader. Comments may also be used to suggest edits in the worksheet. Furthermore, you can set the font size, height, width, etc., of the comments. In this article, you will learn how to add comments to Excel worksheets programmatically using C++.
- C++ API for Adding Comments in Excel Worksheets
- Add Comments in an Excel Worksheet using C++
- Apply Formatting to Comments in an Excel Worksheet using C++
C++ API for Adding Comments in Excel Worksheets
Aspose.Cells for C++ is a native C++ library that allows you to work with Excel files. With the API, you can easily create, read and modify Excel files. Furthermore, you can add comments to your Excel worksheets. To get started, install the API through NuGet or download it directly from the Downloads section.
PM> Install-Package Aspose.Cells.Cpp
Add Comments in an Excel Worksheet using C++
The following are the steps to add a comment to a cell in an Excel worksheet.
- Load the Excel file using the IWorkbook class.
- Retrieve the worksheet where you want to add the comment.
- Add the comment using the IWorksheet->GetIComments()->Add(intrusive_ptrAspose::Cells::Systems::String cellName) method.
- Retrieve the comment added in the previous step using the IWorksheet->GetIComments()->GetObjectByIndex (Aspose::Cells::Systems::Int32 index) method.
- Set the note of the comment using the IComment->SetNote(intrusive_ptrAspose::Cells::Systems::String value) method.
- Save the Excel file using the IWorkbook->Save(intrusive_ptrAspose::Cells::Systems::String fileName) method.
The following sample code shows how to add a comment to a cell in an Excel worksheet using C++.
Apply Formatting to Comments in an Excel Worksheet using C++
The following are the steps to apply formatting to comments in an Excel worksheet using C++.
- Load the Excel file using the IWorkbook class.
- Retrieve the worksheet where you want to add the comment.
- Add the comment using the IWorksheet->GetIComments()->Add(intrusive_ptrAspose::Cells::Systems::String cellName) method.
- Retrieve the comment added in the previous step using the IWorksheet->GetIComments()->GetObjectByIndex (Aspose::Cells::Systems::Int32 index) method.
- Set the note of the comment using the IComment->SetNote(intrusive_ptrAspose::Cells::Systems::String value) method.
- Set the formatting of the comment according to your needs.
- Save the Excel file using the IWorkbook->Save(intrusive_ptrAspose::Cells::Systems::String fileName) method.
The following sample code shows how to apply formatting to a comment in an Excel worksheet using C++.
Get a Free License
In order to try the API without evaluation limitations, you can request a free temporary license.
Conclusion
In this article, you have learned how to add comments in an Excel worksheet using C++. Furthermore, you have seen how to apply formatting to comments using the simple to use Aspose.Cells for C++ API. The API provides a bunch of additional features for working with Excel files that you can explore in detail by visiting the official documentation. In case of any questions, please feel free to reach us at our free support forum.