How to Add Comments in Excel using Python

This quick tutorial guides on how to add comments in Excel using Python by providing the necessary commands to configure the environment. A detailed sequence of steps is provided that assist in performing this task programmatically like the flow of the program is discussed along with the classes and methods. In the last, a runnable sample code is shared to insert a comment in Excel using Python along with the code description that can load an existing XLSX or XLS file and adds a comment at a particular cell in the target worksheet.

Steps to Add Comments in Excel using Python

  1. Configure your environment to use Aspose.Cells for Python via Java
  2. Load the source Excel file in a Workbook class object where comments are to be added
  3. Get access to the target worksheet in the loaded workbook
  4. Get the comments collection in the target worksheet and add a new comment at a target cell
  5. Get a reference to the newly added comment for setting its properties
  6. Set note text in the newly added comment
  7. Save the resultant Excel file on the disk

These steps describe how to add note in Excel using Python by first sharing the instructions to configure the complete environment to run the sample code however you may use the same commands in any of the other environments. A simple sequence is followed like opening a workbook, getting access to the target worksheet and its comments collection, adding a new comment, and setting its desired properties before saving the workbook.

Code to Create a Note in Excel using Python

This code demonstrates how to insert comment in Excel using Python however once you get access to the comments collection, you can not only add comments but also edit or remove a comment as well. The same collection contains methods to add threaded comments available in the latest versions of MS Excel. For an individual comment, you can set a variety of properties like author, HTML note, text horizontal and vertical alignment, text orientation, and comment width also as per your requirements.

This article has taught us to add comments in a worksheet cell. If you want to learn the process to create an Excel file from scratch, refer to the article on how to create Excel file in Python.

 English