Free Support Forum - aspose.com

Textbox Wrap Text in Shape

I am looking for a way how I can tell my Textbox - that I created within a Worksheet - to not wrap its containing text within the Shape/Textbox like I can do in Excel.

Is there a property to set I haven’t found or is this not implemented (yet)?

Thank you in advance.
/Florian


This message was posted using Page2Forum from Aspose.Cells for .NET - Documentation

Hi,

Please use the latest version v5.0.0 with the following sample code, it will not auto-wrap the text in the text box. If you want to wrap text you may use “\n” in the text string you specify.

//Instantiate a new Workbook.
Workbook workbook = new Workbook();

//Get the first worksheet in the book.
Worksheet worksheet = workbook.Worksheets[0];
//Add a new textbox to the collection.
int textboxIndex = worksheet.TextBoxes.Add(2, 1, 160, 200);
//Get the textbox object.
Aspose.Cells.Drawing.TextBox textbox0 = worksheet.TextBoxes[textboxIndex];
//Fill the text without text wrap.
textbox0.Text = “ASPOSE______The .NET & JAVA Component Publisher!”;
//Fill the text with desired text wrap.
//textbox0.Text = “ASPOSE______The .NET & JAVA\n Component Publisher!”;
//Get the textbox text frame.
MsoTextFrame textframe0 = textbox0.TextFrame;
//Set the textbox to adjust it according to its contents.
textframe0.AutoSize = true;
//Set the placement.
textbox0.Placement = PlacementType.FreeFloating;
//Set the font color.
textbox0.Font.Color = Color.Blue;
//Set the font to bold.
textbox0.Font.IsBold = true;
//Set the font size.
textbox0.Font.Size = 14;
//Set font attribute to italic.
textbox0.Font.IsItalic = true;
//Get the filformat of the textbox.
MsoFillFormat fillformat = textbox0.FillFormat;
//Set the fillcolor.
fillformat.ForeColor = Color.Silver;
//Get the lineformat type of the textbox.
MsoLineFormat lineformat = textbox0.LineFormat;
//Set the line style.
lineformat.Style = MsoLineStyle.Single;
//Save the excel file.
workbook.Save(“e:\test\tbox.xls”);


Thank you.

Amjad,

Thank you very much for your reply, it’s a pity Aspose.Cells does not support Auto-Wrapping right now.

/Florian

Hi,

Well, Aspose.Cells for .NET does support to auto-wrap the text, just set the AutoSize property of the text frame to set to false, see the code below:

//Instantiate a new Workbook.
Workbook workbook = new
Workbook();

//Get the first worksheet in the book.

Worksheet worksheet = workbook.Worksheets[0];
//Add a
new textbox to the collection.
int textboxIndex =
worksheet.TextBoxes.Add(2, 1, 160, 200);
//Get the
textbox object.
Aspose.Cells.Drawing.TextBox textbox0 =
worksheet.TextBoxes[textboxIndex];
//Fill the text
without text wrap.
textbox0.Text = “ASPOSE______The .NET
& JAVA Component Publisher!”;
//Fill the text with
desired text wrap.
//textbox0.Text = “ASPOSE______The
.NET & JAVA\n Component Publisher!”;
//Get the
textbox text frame.
MsoTextFrame textframe0 =
textbox0.TextFrame;
//Set the textbox not to adjust it
according to its contents.
textframe0.AutoSize = false;

//Set the placement.
textbox0.Placement =
PlacementType.FreeFloating;
//Set the font color.

textbox0.Font.Color = Color.Blue;
//Set the font to
bold.
textbox0.Font.IsBold = true;
//Set
the font size.
textbox0.Font.Size = 14;

//Set font attribute to italic.
textbox0.Font.IsItalic =
true;
//Get the filformat of the textbox.

MsoFillFormat fillformat = textbox0.FillFormat;
//Set the
fillcolor.
fillformat.ForeColor = Color.Silver;

//Get the lineformat type of the textbox.
MsoLineFormat
lineformat = textbox0.LineFormat;
//Set the line style.

lineformat.Style = MsoLineStyle.Single;
//Save the
excel file.
workbook.Save(“e:\test\tbox.xls”);


Thank you.