我在PowerPoint中创建了一个表格,我想在每个单元格中将文本水平居中。
我使用了MsoHorizo​​ntalAnchor.msoAnchorCenter。

如果文本较短且在单行中,则效果很好,但如果文本较长,则显示为多于1行且未居中。
代码:

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个ligne,您知道如何使文本居中吗?

最佳答案

我将使用此文档“ https://docs.microsoft.com/en-us/office/vba/api/powerpoint.paragraphformat.alignment”。互操作中的TextRange具有称为“ PPParagraphAlignment.ppAlignCenter”的名称,例如:

 textrange.ParagraphFormat.Alignment = PpParagraphAlignment.ppAlignCenter;

关于c# - 以编程方式在单元格中居中:适用于单行文本,但不能使用更长的时间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50234340/

10-17 00:15