Erstellen Sie ein Textfeld, in dem jede Zeile eine andere horizontale Ausrichtung hat
Contents
[
Hide
]
Sie können die horizontale Ausrichtung Ihres Absatztextes mithilfe der TextParagraph.AlignmentType-Eigenschaft festlegen.
Erstellen Sie ein Textfeld, in dem jede Zeile eine andere horizontale Ausrichtung hat.
Der folgende Beispielcode erstellt drei Zeilen und legt die horizontale Ausrichtung jeder von ihnen fest. Bitte laden Sie die durch den Code generierte Ausgabedatei zur Referenz herunter.
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CreateTextBoxhavingdifferentLineAlignment.class); | |
// Create a workbook. | |
Workbook wb = new Workbook(); | |
// Access first worksheet. | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Add text box inside the sheet. | |
ws.getShapes().addShape(MsoDrawingType.TEXT_BOX, 2, 0, 2, 0, 80, 400); | |
// Access first shape which is a text box and set is text. | |
Shape shape = ws.getShapes().get(0); | |
shape.setText( | |
"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. | |
TextParagraph p = shape.getTextBody().getTextParagraphs().get(0); | |
p.setAlignmentType(TextAlignmentType.LEFT); | |
// Acccess the second paragraph and set its horizontal alignment to | |
// center. | |
p = shape.getTextBody().getTextParagraphs().get(1); | |
p.setAlignmentType(TextAlignmentType.CENTER); | |
// Acccess the third paragraph and set its horizontal alignment to | |
// right. | |
p = shape.getTextBody().getTextParagraphs().get(2); | |
p.setAlignmentType(TextAlignmentType.RIGHT); | |
// Save the workbook in xlsx format. | |
wb.save(dataDir + "output.xlsx", SaveFormat.XLSX); |