How to change the Comment Font Color
Contents
[
Hide
]
Microsoft Excel allows users to add comments to cells to add additional information and highlight data. Developers may need to customize the comment to specify alignment settings, text direction Font Color, etc. Aspose.Cells for Python via .NET provides APIs to accomplish the task.
Aspose.Cells for Python via .NET provides a Shape.text_body property to the font color of the comment. The following sample code demonstrates the use of Shape.text_body property to set text direction for a comment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import StyleFlag, TextAlignmentType, Workbook | |
from aspose.pydrawing import Color | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Output directory | |
outputDir = "" | |
# Instantiate a new Workbook | |
workbook = Workbook() | |
# Get the first worksheet | |
worksheet = workbook.worksheets[0] | |
# Add some text in cell A1 | |
worksheet.cells.get("A1").put_value("Here") | |
# Add a comment to A1 cell | |
commentIndex = worksheet.comments.add("A1") | |
comment = worksheet.comments[commentIndex] | |
# Set its vertical alignment setting | |
comment.comment_shape.text_vertical_alignment = TextAlignmentType.CENTER | |
# Set the Comment note | |
comment.note = "This is my Comment Text. This is Test." | |
shape = worksheet.comments.get(0, 0).comment_shape | |
# worksheet.Comments["A1"].CommentShape; | |
shape.fill.solid_fill.color = Color.black | |
font = shape.font | |
font.color = Color.white | |
styleFlag = StyleFlag() | |
styleFlag.font_color = True | |
shape.text_body.format(0, len(shape.text), font, styleFlag) | |
# Save the Excel file | |
workbook.save(outputDir + "outputChangeCommentFontColor.xlsx") |
The output file generated by the above code is attached for your reference.