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 "This is second line Test" will be rendered in the second line"
comment.note = "This is my Comment Text. \nThis is second line Test."
shape = worksheet.comments.get(0, 0).comment_shape
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)
#Set width and height accordingly
shape.width = 300
shape.height = 100
import aspose.cells
from aspose.cells import Workbook, WorksheetCollection, Worksheet, CellsHelper, License, SaveFormat, StyleFlag, TextAlignmentType, BackgroundType
import io
from aspose.pydrawing import Color
# Create a new workbook
workbook = Workbook()
# Access the first worksheet
worksheet = workbook.worksheets[0]
# Add "Hello, World!" to cell A1
worksheet.cells.get("A1").put_value("Hello, World!")
# Define a Style and get the A1 cell style
style = worksheet.cells.get("A1").get_style()
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 "This is second line Test" will be rendered in the second line"
comment.note = "This is my Comment Text. \nThis is second line Test. \nThis is third line"
shape = worksheet.comments.get(0, 0).comment_shape
shape.fill.solid_fill.color = Color.black
font = shape.font
font.color = Color.white
shape.font.is_bold = True
shape.font.name = "Calbri"
shape.font.size = 11
styleFlag = StyleFlag()
styleFlag.font_color = True
styleFlag.font_bold = True
styleFlag.font_name = True
styleFlag.font_size = True
shape.text_body.format(0, len(shape.text), font, styleFlag)
#Set width and height accordingly
shape.width = 300
shape.height = 100
# Create an io.BytesIO stream
stream = io.BytesIO()
# Save the workbook to the stream in Xlsx format
workbook.save(stream, SaveFormat.XLSX)
# Reset the stream position for further use
stream.seek(0)
# Optional: Save the stream content to a file to verify (for demonstration)
with open("e:\\test2\\HelloWorld.xlsx", "wb") as file:
file.write(stream.getvalue())
# Create an io.BytesIO stream
stream = io.BytesIO()
# Save the workbook to the stream in Xlsx format
workbook.save(stream, SaveFormat.XLSX)
# Reset the stream position for further use
stream.seek(0)
# Optional: Save the stream content to a file to verify (for demonstration)
with open("e:\\test2\\HelloWorld.xlsx", "wb") as file:
file.write(stream.getvalue())