I’m not able to set text vertical alignment in table cells. I assumed this was controlled by the TextFrameFormat.AnchoringType property, but it I can’t get it to work as expected.
I asked for assitance through the live chat support, and received the example code below from an Aspose support colleague, which looks like it should work. Unfortunately, when I run this code, the cell text still ends up aligned to the top of the table cell. I have attached an example pptx file that shows both the result of the code, and the (manually adjusted) result that I’m looking for.
What am I doing wrong?
public static void TestTableVertical()
{<span style="color:#2b91af;">Presentation</span> pres = <span style="color:blue;">new</span> <span style="color:#2b91af;">Presentation</span>(<span style="color:#a31515;">"C:\\Temp\\TestVertical.pptx"</span>); <span style="color:green;">//Accessing aslide using its slide position</span> <span style="color:#2b91af;">ISlide</span> slide = pres.Slides[0]; ; <span style="color:blue;">for</span> (<span style="color:blue;">int</span> i = 0; i < slide.Shapes.Count; i++) { <span style="color:blue;">if</span> (slide.Shapes[i] <span style="color:blue;">is</span> <span style="color:#2b91af;">ITable</span>) { <span style="color:#2b91af;">ITable</span> tbl = (<span style="color:#2b91af;">ITable</span>)slide.Shapes[i]; ; <span style="color:green;">//Accessingthe text frame of the first cell of the first row in the table</span> <span style="color:#2b91af;">ITextFrame</span> tf = tbl[0, 0].TextFrame; tf.Text = <span style="color:#a31515;">"Welcome to Aspose.Slides."</span>; <span style="color:green;">//Set textposition to center and vertical</span> <span style="color:green;">// but it doesn't work - text still ends up aligned to the top of the cell</span> tf.TextFrameFormat.AnchoringType = <span style="color:#2b91af;">TextAnchorType</span>.Center; tf.TextFrameFormat.TextVerticalType = <span style="color:#2b91af;">TextVerticalType</span>.Vertical; } } pres.Save(<span style="color:#a31515;">"C:\\Temp\\VerticalAlignIllustration.pptx.pptx"</span>, <span style="color:#2b91af;">SaveFormat</span>.Pptx);
}