Crear un cuadro de texto en el que cada línea tenga una alineación horizontal diferente
Contents
[
Hide
]
Puede establecer la alineación horizontal de su texto de párrafo usando la propiedad TextParagraph.alignment_type
El siguiente código de muestra crea tres líneas y establece la alineación horizontal de cada una de ellas
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, TextAlignmentType, Workbook | |
# 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, 80, 400) | |
# 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.\nCall your friends and family." | |
# Acccess the first paragraph and set its horizontal alignment to left. | |
p = shape.text_body.text_paragraphs[0] | |
p.alignment_type = TextAlignmentType.LEFT | |
# Acccess the second paragraph and set its horizontal alignment to center. | |
p = shape.text_body.text_paragraphs[1] | |
p.alignment_type = TextAlignmentType.CENTER | |
# Acccess the third paragraph and set its horizontal alignment to right. | |
p = shape.text_body.text_paragraphs[2] | |
p.alignment_type = TextAlignmentType.RIGHT | |
# Save the workbook in xlsx format. | |
wb.save(dataDir + "output_out.xlsx", SaveFormat.XLSX) |