libxlsxwriter
|
Cell comments are a way of adding notation to cells in Excel. For example:
The properties of the cell comment can be modified by passing an optional lxw_comment_options struct to worksheet_write_comment_opt()
control the format of the comment. For example:
The following options are available in lxw_comment_options:
author
visible
width
height
x_scale
y_scale
color
font_name
font_size
start_row
start_col
x_offset
y_offset
The options are explained in detail below and shown in comments2.c.
This author
option is used to indicate who is the author of the cell comment. Excel displays the author of the comment in the status bar at the bottom of the worksheet. This is usually of interest in corporate environments where several people might review and provide comments to a workbook:
The default author for all cell comments in a worksheet can be set using the worksheet_set_comments_author()
function:
The visible
option is used to make a cell comment visible when the worksheet is opened. The default behavior in Excel is that comments are initially hidden. However, it is also possible in Excel to make individual comments or all comments visible. In libxlsxwriter individual comments can be made visible as follows:
The visible
property should be set with one of the enum values from lxw_comment_display_types.
It is possible to make all comments in a worksheet visible using the worksheet_show_comments()
worksheet function. Alternatively, if all of the cell comments have been made visible you can hide individual comments:
The width
option is used to set the width of the cell comment box explicitly in pixels:
The width and height can be adjusted together:
The height
option is used to set the height of the cell comment box explicitly in pixels:
The width and height can be adjusted together:
The x_scale
option is used to set the width of the cell comment box as a factor of the default width:
The y_scale
option is used to set the height of the cell comment box as a factor of the default height:
The color
option is used to set the background color of cell comment box. The color should be an RGB integer value, see Working with Colors.
The font_name
option is used to set the font for the comment:
The default font is 'Tahoma'.
The font_size
option is used to set the font size for the comment:
The default font size is 8.
The start_row
option is used to set the row in which the comment will appear. By default Excel displays comments one cell to the right and one cell above the cell to which the comment relates. The row is zero indexed:
See Notes on scaling of cell comments
The start_col
option is used to set the column in which the comment will appear. By default Excel displays comments one cell to the right and one cell above the cell to which the comment relates. The column is zero indexed:
See Notes on scaling of cell comments
The x_offset
option is used to change the x offset, in pixels, of a comment within a cell:
See Notes on scaling of cell comments
The y_offset
option is used to change the y offset, in pixels, of a comment within a cell:
See Notes on scaling of cell comments
Note on options that move a cell position:
Excel only displays offset cell comments when they are displayed as visible
. Excel does not display hidden cells as displaced when you mouse over them. Please note this when using options that adjust the position of the cell comment such as start_row
, start_col
, x_offset
and y_offset
.
Note on row height and comments:
If you specify the height of a row that contains a comment then libxlsxwriter will adjust the height of the comment to maintain the default or user specified dimensions. However, the height of a row can also be adjusted automatically by Excel if the text wrap property is set or large fonts are used in the cell. This means that the height of the row is unknown to the library at run time and thus the comment box is stretched with the row. Use the worksheet_set_row()
function to specify the row height explicitly and avoid this problem. See Example 8 of comments2.c.