设置形状或文本框中段落的行间距
Contents
[
Hide
]
您可以使用TextParagraph.LineSpace、TextParagraph.SpaceBefore和TextParagraph.SpaceAfter属性分别设置段落的行间距、前置距离和后置距离,其中TextParagraph类。
以下示例代码解释了所述属性的用法。
This file contains 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, 100, 200); | |
// 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."; | |
// Acccess the first paragraph | |
TextParagraph p = shape.TextBody.TextParagraphs[1]; | |
// Set the line space | |
p.LineSpaceSizeType = LineSpaceSizeType.Points; | |
p.LineSpace = 20; | |
// Set the space after | |
p.SpaceAfterSizeType = LineSpaceSizeType.Points; | |
p.SpaceAfter = 10; | |
// Set the space before | |
p.SpaceBeforeSizeType = LineSpaceSizeType.Points; | |
p.SpaceBefore = 10; | |
// Save the workbook in xlsx format | |
wb.Save(dataDir + "output_out.xlsx", SaveFormat.Xlsx); |