Auto-Resize All Text within Table Cells to the Font Size of the Cell with the Smallest Font

Hello,

I have a requirement whereby I want all the text within a table’s cells to be the same font size, especially after it has been auto-shrunk to fit. In this case, I was hoping to loop thru all table cells to determine the FontHeight and then use the smallest FontHeight to then modify all other cell’s FontHeights to the smallest. Basically, we don’t want different FontHeights for different cells as it does not look good.

When I manually set a cell’s FontHeight then it seems to return a height when I log it to console. However, if I don’t set FontHeight it returns NaN which is not very helpful.

tbl.getRows().get_Item(1).get_Item(1).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFontHeight()

What is the best way to achieve what I need here?

Thanks in advance,
Aaron

@mully74,
Thank you for posting the question.

Many presentation object formatting properties in PowerPoint documents use property inheritance from parent elements. When FontHeight returns NaN, it means that the font height is not set and is inherited from the paragraph. Typically you can use the getEffective method to retrieve the actual formatting property values. In your case:
tbl.getRows().get_Item(1).get_Item(1).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getEffective().getFontHeight()

Examples:

Thank you Audrey, much appreciated.

However, I still cannot effectively detect whether a table cell’s text has overflowed i.e. Slides (or Powerpoint) has applied autofit and therefore automatically reduced the font to whatever.

Basically, I’m wanting to detect when a table cell’s text has been autofit (font reduced).

Is there any easy way to achieve that?

Thank you,
Aaron

@mully74,
You can try using the getAutofitType method from the ITextFrameFormat interface like this:

var textFrameFormat = autoShape.getTextFrame().getTextFrameFormat();
var autofitType = textFrameFormat.getAutofitType();

It returns a value from the TextAutofitType enumeration.

I hope this will help you.