Set Line Spacing of the Paragraph in a Shape or Textbox
Contents
[
Hide
]
You can set the line space of the paragraph, its space before and space after using the TextParagraph.line_space, TextParagraph.space_before and TextParagraph.space_after properties of the TextParagraph class.
The following sample code explains the usage of the mentioned properties.
This file contains hidden or 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 SaveFormat, Workbook | |
from aspose.cells.drawing.texts import LineSpaceSizeType | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create a workbook | |
wb = Workbook() | |
# Access first worksheet | |
ws = wb.worksheets[0] | |
# Add text box inside the sheet | |
ws.shapes.add_text_box(2, 0, 2, 0, 100, 200) | |
# Access first shape which is a text box and set is text | |
shape = ws.shapes[0] | |
shape.text = "Sign up for your free phone number.\nCall and text online for free." | |
# Acccess the first paragraph | |
p = shape.text_body.text_paragraphs[1] | |
# Set the line space | |
p.line_space_size_type = LineSpaceSizeType.POINTS | |
p.line_space = 20.0 | |
# Set the space after | |
p.space_after_size_type = LineSpaceSizeType.POINTS | |
p.space_after = 10.0 | |
# Set the space before | |
p.space_before_size_type = LineSpaceSizeType.POINTS | |
p.space_before = 10.0 | |
# Save the workbook in xlsx format | |
wb.save(dataDir + "output_out.xlsx", SaveFormat.XLSX) |