Autosizing text to fit table cell

Hi,

A little background; we’ve decided to use a template pptx file containing tables that is filled in with the information out of a DB and made available to the user. The problem is that text in a table cell doesn’t appear to be auto-sizable; the shape (table.cell) autosizes to fit the text. I believe this is a limitation of PowerPoint and not just Aspose.Slides as described in this forum post.

I figured the most direct approach would be creating a function that accepts the cell’s height, width and desired text, create a rectangle with those dimensions and text, and then return the font size that would be used in the rectangle’s text for the cell. Pretty straightforward, but I can’t seem to get it to work… it always return a font size of 18, which I believe is the default.

public float getFontSize(float h, float w, string text)
{
float size;

//test
text = “This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text.”;
h = 50;
w = 50;

PresentationEx pres = new PresentationEx();
SlideEx sld = pres.Slides[0];

int idx = sld.Shapes.AddAutoShape(ShapeTypeEx.Rectangle, w, h, w, h);
AutoShapeEx ashp = (AutoShapeEx)sld.Shapes[idx];
ashp.AddTextFrame(“frame”);

TextFrameEx txtFrame = ashp.TextFrame;

txtFrame.AutofitType = TextAutofitTypeEx.Normal;

ParagraphEx para = txtFrame.Paragraphs[0];

PortionEx portion = para.Portions[0];

portion.Text = text;

size = portion.CreatePortionFormatData().FontHeight;

return size;
}

Am I missing something super obvious here?

Thanks for any assistance.

Smith

Hi Smith,

Thanks for inquiring Aspose.Slides.

I have worked over the requirements shared by you. It seems to be an issue with Aspose.Slides while retrieving the font height. An issue with ID SLIDESNET-34626 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be automatically notified once the issue will be resolved. It seems that when you set the AutoFitType to Normal, PowerPoint internally manages the font height for the text added in the shape when it is opened in PowerPoint. If you try adding the following statement for saving the presentation to file before return statement, you will observe that font height is right when opened in PowerPoint.

pres.Write(“D:\Aspose Data\Testpres.pptx”);

Many Thanks,