各行の水平方向の配置が異なる TextBox を作成する
Contents
[
Hide
]
を使用して、段落テキストの水平方向の配置を設定できます。TextParagraph.AlignmentType財産。
次のサンプル コードは、3 つの行を作成し、それぞれの水平方向の配置を設定します。
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook. | |
Workbook wb = new Workbook(); | |
// Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
// Add text box inside the sheet. | |
ws.Shapes.AddTextBox(2, 0, 2, 0, 80, 400); | |
// Access first shape which is a text box and set is text. | |
Shape 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. | |
TextParagraph p = shape.TextBody.TextParagraphs[0]; | |
p.AlignmentType = TextAlignmentType.Left; | |
// Acccess the second paragraph and set its horizontal alignment to center. | |
p = shape.TextBody.TextParagraphs[1]; | |
p.AlignmentType = TextAlignmentType.Center; | |
// Acccess the third paragraph and set its horizontal alignment to right. | |
p = shape.TextBody.TextParagraphs[2]; | |
p.AlignmentType = TextAlignmentType.Right; | |
// Save the workbook in xlsx format. | |
wb.Save(dataDir + "output_out.xlsx", SaveFormat.Xlsx); |