我在PowerPoint中创建了一个表,我想在每个单元格中水平居中文本。我使用了MsoHorizontalAnchor.msoAnchorCenter。
如果文本很短且在一行中,它可以很好地工作但如果文本很长,它会显示在多行中并且不会居中。代码:
myShape.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = "shortOK";
myShape.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = "Long text is not displayed centered";
myShape.Table.Cell(1, 1).Shape.TextFrame.VerticalAnchor = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorMiddle;
myShape.Table.Cell(1, 2).Shape.TextFrame.VerticalAnchor = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorMiddle;
myShape.Table.Cell(1, 1).Shape.TextFrame.HorizontalAnchor = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorCenter;
myShape.Table.Cell(1, 2).Shape.TextFrame.HorizontalAnchor = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorCenter;
如果以1个以上的方式显示,您知道如何保持文本居中吗?
我会使用这个文档,“https://docs.microsoft.com/en-us/office/vba/api/powerpoint.paragraphformat.alignment”。 interop中的TextRange有一个名为“PPParagraphAlignment.ppAlignCenter”的东西,例如:
textrange.ParagraphFormat.Alignment = PpParagraphAlignment.ppAlignCenter;