如何使用c#保留powerpoint幻灯片的texthape格式的格式

时间:2013-06-28 14:43:51

标签: c# interop powerpoint office-interop

我正在使用c#interop来获取形状文本的页面内容,使用以下代码:

var textRange = shape.TextFrame.TextRange;
var text = textRange.Text;

其中text包含textshape的文本。但所有格式都消失了。 :(

我们使用自己的编辑器修改内容,并使用更改的内容创建ppt:

string strToReplace = StripTagsRegex(xmlTempNode.InnerText);
strToReplace = strToReplace.Replace(" ", " ");
shape.TextFrame.TextRange.Text = strToReplace;//load new text to shape

我在最终输出中得到了所需的文本(即生成的ppt)。但是所有的对齐,pragraphs,格式化都没有了。有没有办法保存它?

感谢您停止...... !!

1 个答案:

答案 0 :(得分:1)

如果要替换PowerPoint形状中的文本并保留格式,请使用PowerPoint自己的替换方法。

在VBA中:

With Shape.TextFrame.TextRange
  .Replace "this text", "with this text"
End With