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.
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()
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).
Out of interest, I am able to detect a change in cell “height” using Cell.getHeight() however, upon setting a long text value that autosizes, are not able to pickup the effective font height. Either the font stays the same size and wraps and pushes my table down OR it resizes but I don’t get new font size. And now for some reason Powerpoint won’t let me change the Text Type to “Shrink text on overflow”. I’ve even tried setting this programmatically but with no joy, but I will try again.
Might need to send you my sample template and code. That might make it easier.
@mully74,
Thank you for the files. It looks like PowerPoint does not allow you to set “Shrink text on overflow” and “Wrap text in shape” options for text in table cells. Therefore, the font is never “reduced” in table cells.