- Python XlsxWriter - VBA Macro
- Python XlsxWriter - Working with Pandas
- Python XlsxWriter - Cell Comments
- Python XlsxWriter - Header & Footer
- Python XlsxWriter - Page Setup
- Python XlsxWriter - Insert Image
- Python XlsxWriter - Textbox
- Python XlsxWriter - Hide/Protect Worksheet
- Python XlsxWriter - Freeze & Split Panes
- Python XlsxWriter - Outlines & Grouping
- Python XlsxWriter - Data Validation
- Python XlsxWriter - Sparklines
- Python XlsxWriter - Pie Chart
- Python XlsxWriter - Line Chart
- Python XlsxWriter - Bar Chart
- Python XlsxWriter - Chart Legends
- Python XlsxWriter - Chart Formatting
- Python XlsxWriter - Adding Charts
- Python XlsxWriter - Conditional Formatting
- Python XlsxWriter - Hyperlinks
- Python XlsxWriter - Border
- Python XlsxWriter - Number Formats
- Python XlsxWriter - Fonts & Colors
- Python XlsxWriter - Applying Filter
- Python XlsxWriter - Tables
- Python XlsxWriter - Date and Time
- Python XlsxWriter - Formula & Function
- Python XlsxWriter - Defined Names
- Python XlsxWriter - Cell Notation & Ranges
- Python XlsxWriter - Important classes
- Python XlsxWriter - Hello World
- Python XlsxWriter - Environment Setup
- Python XlsxWriter - Overview
- Python XlsxWriter - Home
Python XlsxWriter Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Python XlsxWriter - Cell Comments
In an Excel worksheet, comments can be inserted for various reasons. One of the uses is to explain a formula in a cell. Also, Excel comments also serve as reminders or notes for other users. They are useful for cross-referencing with other Excel workbooks.
From Excel s menu system, comment feature is available on Review menu in the ribbon.
To add and format comments, XlsxWriter has add_comment() method. Two mandatory parameters for this method are cell location (either in A1 type or row and column number), and the comment text.
Example
Here is a simple example −
import xlsxwriter wb = xlsxwriter.Workbook( hello.xlsx ) ws = wb.add_worksheet() data= XlsxWriter Library ws.set_column( C:C , 25) ws.set_row(2, 50) ws.write( C3 , data) text = Developed by John McNamara ws.write_comment( C3 , text) wb.close()
Output
When we open the workbook, a comment will be seen with a marker on top right corner of C3 cell when the cursor is placed in it.
By default, the comments are not visible until the cursor hovers on the cell in which the comment is written. You can either show all the comments in a worksheet by invoking show_comment() method of worksheet object, or setting visible property of inspanidual comment to True.
ws.write_comment( C3 , text, { visible : True})
Example
In the following code, there are three comments placed. However, the one in cell C3 is has been configured with visible property set to False. Hence, it cannot be seen until the cursor is placed in the cell.
import xlsxwriter wb = xlsxwriter.Workbook( hello.xlsx ) ws = wb.add_worksheet() ws.show_comments() data= Python ws.set_column( C:C , 25) ws.set_row(0, 50) ws.write( C1 , data) text = Programming language developed by Guido Van Rossum ws.write_comment( C1 , text) data= XlsxWriter ws.set_row(2, 50) ws.write( C3 , data) text = Developed by John McNamara ws.write_comment( C3 , text, { visible :False}) data= OpenPyXl ws.set_row(4, 50) ws.write( C5 , data) text = Developed by Eric Gazoni and Charpe Clark ws.write_comment( C5 , text, { visible :True}) wb.close()
Output
It will produce the following output −
You can set author option to indicate who is the author of the cell comment. The author of the comment is also displayed in the status bar at the bottom of the worksheet.
worksheet.write_comment( C3 , Atonement , { author : Tutorialspoint })
The default author for all cell comments can be set using the set_comments_author() method −
worksheet.set_comments_author( Tutorialspoint )
It will produce the following output −
Advertisements