Interface ITextFrame
Returns a TextFrame object that contains the alignment and anchoring properties for the specified shape. Read-only.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.NET.dll
Syntax
public interface ITextFrame
Properties
BottomMarginPt
Gets or sets bottom margin of the text frame
Declaration
int BottomMarginPt { get; set; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates how to set the bottom margin for the text inside the shape using BottomMarginPt
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 70);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set margin
textFrame.BottomMarginPt = 14;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
HorizontalAlignment
Gets or sets horizontal alignment in the text frame.
Declaration
ExcelHorizontalAlignment HorizontalAlignment { get; set; }
Property Value
Type |
---|
ExcelHorizontalAlignment |
Examples
By default Left is set to HorizontalAlignment
. Here for example, we set Right
to HorizontalAlignment
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set text range
ITextRange textRange = textFrame.TextRange;
//Set text
textRange.Text = "Sample";
//Set alignment
textFrame.HorizontalAlignment = ExcelHorizontalAlignment.Left;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
IsAutoMargins
Gets or sets auto margin of the text frame
Declaration
bool IsAutoMargins { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to access IsAutoMargin
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 20, 70);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set margin
textFrame.MarginLeftPt = 14;
//Check IsAutoMargins
Console.Write(textFrame.IsAutoMargins);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//False
IsAutoSize
Gets or sets autosize in the text frame
Declaration
bool IsAutoSize { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to set IsAutoSize
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set text
textFrame.TextRange.Text = "Sample";
//Set auto size
textFrame.IsAutoSize = true;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
IsTextOverFlow
Gets or sets overflow of the text frame[Used internally].
Declaration
bool IsTextOverFlow { get; set; }
Property Value
Type |
---|
System.Boolean |
MarginLeftPt
Gets or sets left margin of the text frame
Declaration
int MarginLeftPt { get; set; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates how to set the left margin for the text inside the shape using MarginLeftPt
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 20, 70);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set margin
textFrame.MarginLeftPt = 14;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
RightMarginPt
Gets or sets right margin of the text frame
Declaration
int RightMarginPt { get; set; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates how to set the right margin for the text inside the shape using RightMarginPt
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 20, 70);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set margin
textFrame.RightMarginPt = 14;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
TextDirection
Gets or sets text direction of the text frame.
Declaration
TextDirection TextDirection { get; set; }
Property Value
Type |
---|
TextDirection |
Examples
By default Horizontal is set to TextDirection
. Here for example, we set RotateAllText90
to TextDirection
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 100, 30);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set text range
ITextRange textRange = textFrame.TextRange;
//Set text
textRange.Text = "Sample";
//Set text direction
textFrame.TextDirection = TextDirection.RotateAllText90;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
TextHorzOverflowType
Gets or sets horizontal text overflow in the text frame.
Declaration
TextHorzOverflowType TextHorzOverflowType { get; set; }
Property Value
Type |
---|
TextHorzOverflowType |
Examples
By default OverFlow is set to TextHorzOverflowType
property. Here for example, we set Clip
to TextHorzOverflowType
.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 20, 70);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set text
textFrame.TextRange.Text = "Sample Text in shape";
//Set clip
textFrame.TextHorzOverflowType = TextHorzOverflowType.Clip;
//Set wrap
textFrame.WrapTextInShape = false;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
TextRange
Gets text range of the text frame.
Declaration
ITextRange TextRange { get; }
Property Value
Type |
---|
ITextRange |
Examples
The following code illustrates how to set Text by accessing TextRange
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set text range
ITextRange textRange = textFrame.TextRange;
//Set text
textRange.Text = "Sample text";
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
TextVertOverflowType
Gets or sets vertical text overflow in the text frame.
Declaration
TextVertOverflowType TextVertOverflowType { get; set; }
Property Value
Type |
---|
TextVertOverflowType |
Examples
By default OverFlow is set to TextVertOverflowType
property. Here for example, we set Ellipsis
to TextVertOverflowType
.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set text range
ITextRange textRange = textFrame.TextRange;
//Set text
textRange.Text = "Sample Sample Sample Sample Sample Sample Sample";
//Set overflow type
textFrame.TextVertOverflowType = TextVertOverflowType.Ellipsis;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
TopMarginPt
Gets or sets top margin of the text frame
Declaration
int TopMarginPt { get; set; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates how to set the top margin for the text inside the shape using TopMarginPt
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 70);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set margin
textFrame.TopMarginPt = 14;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
VerticalAlignment
Gets or sets vertical alignment in the text frame.
Declaration
ExcelVerticalAlignment VerticalAlignment { get; set; }
Property Value
Type |
---|
ExcelVerticalAlignment |
Examples
By default Top is set to VerticalAlignment
. Here for example, we set Bottom
to VerticalAlignment
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set text range
ITextRange textRange = textFrame.TextRange;
//Set text
textRange.Text = "Sample";
//Set alignment
textFrame.VerticalAlignment = ExcelVerticalAlignment.Bottom;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
WrapTextInShape
Gets or sets wrap text in the text frame
Declaration
bool WrapTextInShape { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to set WrapTextInShape
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 20, 70);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set text
textFrame.TextRange.Text = "Sample Text in shape";
//Set clip
textFrame.TextHorzOverflowType = TextHorzOverflowType.Clip;
//Set wrap
textFrame.WrapTextInShape = false;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}