Textformating within Textbox is not working

Hello technical support team,


I tried to add a textbox to excel with formating the text, but the formating is not working.

Here is the code:
Shape shape = worksheet.Shapes.AddTextBox(2, 0, 5, 0, 100, 200);
string text = “Best.Nr.T875351\n(36 Stück)”;
shape.Text = text;
shape.Font.Name = “Tahoma”;
shape.Font.Size = 10;
shape.Font.IsBold = true;
shape.Font.IsItalic = true;
shape.TextHorizontalAlignment = TextAlignmentType.Center;
shape.TextVerticalAlignment = TextAlignmentType.Center;

And here is the result:
1. Attachment (fontname, fontsize, bold and italic is not working, textallignment of second line is not working)
2. Attachment, wished result.


Hi,


Thanks for the sample code, screenshots and details.

Please try the following sample code with our latest version/fix: Aspose.Cells for .NET v17.4.x, it works fine as I tested as per your requirements:
e.g
Sample code:

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

Shape shape = worksheet.Shapes.AddTextBox(2, 0, 5, 0, 100, 200);
string text = “Best.Nr.T875351\n(36 Stück)”;
shape.Text = text;
shape.TextHorizontalAlignment = TextAlignmentType.Center;
shape.TextVerticalAlignment = TextAlignmentType.Center;
TextParagraphCollection paragraphs = shape.TextBody.TextParagraphs;
for(int i =0; i<paragraphs.Count; i++)
{
TextParagraph p = paragraphs[i];
p.Font.Name = “Tahoma”;
p.Font.Size = 10;
p.Font.IsBold = true;
p.Font.IsItalic = true;
}
workbook.Save(“e:\test2\out1.xlsx”);


The output file is also attached.

Thank you.
Hi,

thanks for the quick reply, with your code and the new version, it works fine.

Kind regards
Jens

Hi,


Good to know that your issue is sorted out by the suggested code. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.

Hi,


Thanks for using Aspose.Cells.

You can also use Shape.Font property to apply the font to your shape. Here is the sample code and its output Excel file for your reference.

C#
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Shape shape = worksheet.Shapes.AddTextBox(2, 0, 5, 0, 100, 200);
string text = “Best.Nr.T875351\n(36 Stück)”;
shape.Text = text;
Aspose.Cells.Font font = shape.Font;
font.Name = “Tahoma”;
font.Size = 10;
font.IsBold = true;
font.IsItalic = true;
shape.Font = font;
shape.TextHorizontalAlignment = TextAlignmentType.Center;
shape.TextVerticalAlignment = TextAlignmentType.Center;

workbook.Save(“dest.xlsx”);