小编Fre*_*low的帖子

以编程方式在单元格中居中文本:适用于单行文本,但不会持续更长时间

我在 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;
Run Code Online (Sandbox Code Playgroud)

如果显示在 1 法以内,您知道如何使文本居中吗?

c# powerpoint office-interop

2
推荐指数
1
解决办法
525
查看次数

标签 统计

c# ×1

office-interop ×1

powerpoint ×1