我正在编写一个打开 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 数据。
如果您有澄清问题,请告诉我。