Interface ITextRange
Returns the TextRange object that represents the text in the object. Read-only.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.Portable.dll
Syntax
public interface ITextRange
Properties
RichText
Text of the comment. Read-only.
Declaration
IRichTextString RichText { get; }
Property Value
Type |
---|
IRichTextString |
Examples
The following code illustrates how to set RichText
inside the IShape.
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 rich text
IRichTextString richText = textRange.RichText;
richText.Text = "Sample";
//Create font
IFont font = workbook.CreateFont();
font.Color = ExcelKnownColors.Red;
//Apply rich text format
richText.SetFont(0, 5, font);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
Text
Gets or sets the text property of the text range.
Declaration
string Text { get; set; }
Property Value
Type |
---|
System.String |
Examples
The following code illustrates how to set Text
inside the IShape.
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();
}