Hi there,
I’m using aspose.slides version 6.9.0 and am testing the new setAutofitType-function for the textframes. It works fine with textframes from AutoShapeEx-Object.
What I would need is to use it for textframes in tables. I have a defined table layout with specific row heights. The text inside the cells should autoFit it’s font size so it fits into the cell without enlarging the row height. Is this not supported? Or how can I stop the cell height form growing larger with it’s content?
Thanks in advance,
Christiane Eckl
Hi Christiane Eckl,
Hi,
I would like it to work like this:
final PresentationEx pres = new PresentationEx();
final SlideEx slide2 = pres.getSlides().get_Item(0);
final double[] columnWidths = new double[] { 300 };
final double[] rowHeights = new double[] { 200, 10 };
final int tableIdx = slide2.getShapes().addTable(50f, 50f, columnWidths, rowHeights);
final TableEx table2 = (TableEx) slide2.getShapes().get_Item(tableIdx);
TextFrameEx textframe = table2.get_Item(0, 0).getTextFrame();
textframe.setAutofitType(TextAutofitTypeEx.Normal);
textframe.setText(“LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE”);
pres.write(“C:\_temp\_pptx\autofit.pptx”);
This should keep the row and cell height to the defined 200px, and reduce the text’s font size until it fits into the cell without making the cell larger.
But unfortunately, this doesn’t work. The only workaround I currently found is to save the initial height and manually reduce the font size und set it to a minimalHeight until it fits. But I was hoping the setAutofitType function would do that for me.
Thanks,
Christiane
Hi Christiane,
public static void genTable(){String path2=“D:\Aspose Data\”;final PresentationEx pres = new PresentationEx();final SlideEx slide2 = pres.getSlides().get_Item(0);final double[] columnWidths = new double[] { 300 };final double[] rowHeights = new double[] { 200, 10 };final int Idx = slide2.getShapes().addAutoShape(ShapeTypeEx.Rectangle, 200, 200, 250, 250);final AutoShapeEx table2 = (AutoShapeEx) slide2.getShapes().get_Item(Idx);TextFrameEx textframe = table2.getTextFrame();textframe.setAutofitType(TextAutofitTypeEx.Normal);textframe.setText(“LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE LONG HEADLINE”);textframe.setAutofitType(TextAutofitTypeEx.Shape);pres.write(path2+“autofit3.pptx”);}
Hi Mudassir,
thanks for your detailed answer! I just wanted to be sure, that there’s no other way.
Maybe we can change our logic to use AutoShapeEx-Objects, or we’ll implement our own solution.
Thanks,
Christiane
Hi Christiane,