Posted By

sherazam on 07/27/16


Tagged

file files Net set a line Processing excel paragraph api in of Shape textBox spacing xlsx


Versions (?)

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


 / Published in: C#
 

URL: http://www.aspose.com/products/cells/net

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.

  1. //[C# Code]
  2.  
  3. // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
  4. // The path to the documents directory.
  5. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  6.  
  7. // Create a workbook
  8. Workbook wb = new Workbook();
  9.  
  10. // Access first worksheet
  11. Worksheet ws = wb.Worksheets[0];
  12.  
  13. // Add text box inside the sheet
  14. ws.Shapes.AddTextBox(2, 0, 2, 0, 100, 200);
  15.  
  16. // Access first shape which is a text box and set is text
  17. Shape shape = ws.Shapes[0];
  18. shape.Text = "Sign up for your free phone number.\nCall and text online for free.";
  19.  
  20. // Acccess the first paragraph
  21. TextParagraph p = shape.TextBody.TextParagraphs[1];
  22.  
  23. // Set the line space
  24. p.LineSpaceSizeType = LineSpaceSizeType.Points;
  25. p.LineSpace = 20;
  26.  
  27. // Set the space after
  28. p.SpaceAfterSizeType = LineSpaceSizeType.Points;
  29. p.SpaceAfter = 10;
  30.  
  31. // Set the space before
  32. p.SpaceBeforeSizeType = LineSpaceSizeType.Points;
  33. p.SpaceBefore = 10;
  34.  
  35. // Save the workbook in xlsx format
  36. wb.Save(dataDir + "output_out_.xlsx", SaveFormat.Xlsx);
  37.  
  38. //[VB.NET Code]
  39.  
  40. ' For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
  41. ' The path to the documents directory.
  42. Dim dataDir As String = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
  43.  
  44. ' Create a workbook
  45. Dim wb As New Workbook()
  46.  
  47. ' Access first worksheet
  48. Dim ws As Worksheet = wb.Worksheets(0)
  49.  
  50. ' Add text box inside the sheet
  51. ws.Shapes.AddTextBox(2, 0, 2, 0, 100, 200)
  52.  
  53. ' Access first shape which is a text box and set is text
  54. Dim shape As Shape = ws.Shapes(0)
  55. shape.Text = "Sign up for your free phone number." & vbLf & "Call and text online for free."
  56.  
  57. ' Acccess the first paragraph
  58. Dim p As TextParagraph = shape.TextBody.TextParagraphs(1)
  59.  
  60. ' Set the line space
  61. p.LineSpaceSizeType = LineSpaceSizeType.Points
  62. p.LineSpace = 20
  63.  
  64. ' Set the space after
  65. p.SpaceAfterSizeType = LineSpaceSizeType.Points
  66. p.SpaceAfter = 10
  67.  
  68. ' Set the space before
  69. p.SpaceBeforeSizeType = LineSpaceSizeType.Points
  70. p.SpaceBefore = 10
  71.  
  72. ' Save the workbook in xlsx format
  73. wb.Save(dataDir & Convert.ToString("output_out_.xlsx"), SaveFormat.Xlsx)

Report this snippet  

You need to login to post a comment.