我正在编写一个应用程序打开powerpoint演示文稿,找到形状列表,并将TextFrame的内容转换为Rtf。我很容易从TextFrame中获取文本。以下代码效果很好。
string strFilePath = @"i:\work\test1.pptx";
PowerPoint.Application PowerPoint_App = new PowerPoint.Application();
try
{
PowerPoint_App.Visible = Office.MsoTriState.msoFalse;
}
catch { }
PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations;
PowerPoint.Presentation presentation = multi_presentations.Open(strFilePath, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);
for (int i = 0; i < presentation.Slides.Count; i++)
{
foreach (PowerPoint.Shape shape in presentation.Slides[i + 1].Shapes)
{
switch (shape.Type)
{
case Office.MsoShapeType.msoTextBox:
if (shape.TextFrame.TextRange.Text.Length > 1)
{
Console.WriteLine("(x=" + shape.Left.ToString() + ", y=" + shape.Top.ToString() + ",
w=" + shape.Width.ToString() + ", h=" + shape.Height.ToString() + ")\n" +
shape.TextFrame.TextRange.Text + "\n");
}
break;
}
}
}
PowerPoint_App.Quit();
但是我需要将TextFrame的内容作为Rtf数据输出。我尝试过以下方法:
shape.TextFrame.TextRange.Copy();
string strRtfData = Clipboard.GetText(TextDataFormat.Rtf);
在此之后,字符串为空。我想要的是在字符串中包含Rtf数据。
如果您有澄清问题,请与我们联系。
答案 0 :(得分:0)