article

How to Set Line Spacing of a Paragraph in a Shape or Textbox inside .NET Apps

Email
Submitted on: 7/27/2016 6:41:28 AM
By: Sherazam  
Level: Intermediate
User Rating: Unrated
Compatibility: C#, VB.NET
Views: 2707
 
     This technical tip shows how to Set Line Spacing of the Paragraph in a Shape or Textbox in .NET applications. You can set the line space of the paragraph, its space before and space after using the TextParagraph.LineSpace, TextParagraph.SpaceBefore and TextParagraph.SpaceAfter respectively. The following example shows how to Set Line Spacing of the Paragraph in a Shape or Textbox.

 
				This technical tip shows how to Set Line Spacing of the Paragraph in a Shape or Textbox in .NET applications. You can set the line space of the paragraph, its space before and space after using the TextParagraph.LineSpace, TextParagraph.SpaceBefore and TextParagraph.SpaceAfter respectively. The following example shows how to Set Line Spacing of the Paragraph in a Shape or Textbox.
[C#]
 
// 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); 
[VB]
' For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
' Create a workbook
Dim wb As New Workbook()
' Access first worksheet
Dim ws As Worksheet = 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
Dim shape As Shape = ws.Shapes(0)
shape.Text = "Sign up for your free phone number." & vbLf & "Call and text online for free."
' Acccess the first paragraph
Dim p As TextParagraph = 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 & Convert.ToString("output_out_.xlsx"), SaveFormat.Xlsx) 
More about Aspose.Cells for .NET


Other 44 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.