Calculate text size

Hi,

I am trying to limit the size of a text box that is included in a chart. Is there a way hide the text portion that is outside the textbox area? If it is not, is there a way to obtain the size of the text so I can truncate it? Maybe something similar to Graphics.MeasureString, but applied to the textbox?

Thanks in advance

Hi,

When you use the following code lines, the textbox will be extended to adjust itself to show all the contents etc and if the size of the text box is not auto sized, the text will not be outside the textbox area. So if the text box could not display all value, rest of the data will be truncated.

MsoTextFrame textframe0 = textbox0.TextFrame;
//Set the textbox to adjust it according to its contents.
textframe0.AutoSize = true;


Please try Aspose.Cells for .NET (Latest Version)

If the problem is still there, share the sample project.

Hi,
I have several textboxes with dynamic size. What I want is to keep that size and hide the text that is outside the textbox area, so I do not want to use AutoSize.
I am including a sample that contains a chart with a textbox with some fixed size. After setting a text, I would not like to see the text outside the textbox area.

string inputName = “TextboxSize.xlsx”;
string outputName = “TextboxSize-After.xlsx”;
Workbook workbook = new Workbook(inputName);
Aspose.Cells.Charts.Chart chart = workbook.Worksheets[1].Charts[0];
Aspose.Cells.Drawing.TextBox textBox = (Aspose.Cells.Drawing.TextBox)chart.Shapes[0];
textBox.TextFrame.AutoSize = false;
textBox.Text = “This is a long text”;
workbook.Save(outputName, SaveFormat.Xlsx);

Thanks

Hi,

Thanks for providing us the sample files.

After closely looking into your issue, we found there
were some settings of processing overflow text that we do not support at the moment. We will support such settings soon.<o:p></o:p>


We have logged it into our issue tracking system with an id: CELLSNET-18979.



Thank you.



Hi,

As we have logged the issue, in the mean while you can get the font size by using following code:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

string inputName = "M:\\AsposeTrash\\TextboxSize.xlsx";

string outputName = "M:\\AsposeTrash\\TextboxSize-After111.xlsx";

Workbook workbook = new Workbook(inputName);

Aspose.Cells.Charts.Chart chart = workbook.Worksheets[1].Charts[0];

Aspose.Cells.Drawing.TextBox textBox = (Aspose.Cells.Drawing.TextBox)chart.Shapes[0];

// Get the Font Size of the textbox

string sTxtSize = textBox.Font.Size.ToString();

// Update the Font size

textBox.Font.Size = 15;

textBox.TextFrame.AutoSize = false;

textBox.Text = "This is a long text";

workbook.Save(outputName, SaveFormat.Xlsx);

Thanks,

Hi Pablo,

We have fixed the issue regarding shape's text overflow type. Please try the attached version.
Please use "Shape.TextVerticalOverflow" attribute to get/set the text vertical overflow type of the textbox.
The default value is TextOverflowType.Clip. Currently this attribute only works for xlsx/xlsm file format.


Thank you,