使用Office Automation,将文本框形状导出为Rtf
我正在编写一个应用程序,用于打开powerpoint演示文稿,查找形状列表,并将文本框的内容转换为Rtf。我可以很容易地从文本框中获取文本。下面的代码非常有效使用Office Automation,将文本框形状导出为Rtf,automation,export,powerpoint,rtf,Automation,Export,Powerpoint,Rtf,我正在编写一个应用程序,用于打开powerpoint演示文稿,查找形状列表,并将文本框的内容转换为Rtf。我可以很容易地从文本框中获取文本。下面的代码非常有效 string strFilePath = @"i:\work\test1.pptx"; PowerPoint.Application PowerPoint_App = new PowerPoint.Application(); try { PowerPoint_App.Visible = Office.MsoTriState.ms
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();
但在此之后,字符串为空。我想要的是字符串中的Rtf数据
如果您有澄清问题,请告诉我。您需要在复制之前选择一些内容: 编辑:我想这是正确的链接:
shape.TextFrame.TextRange.Copy();
string strRtfData = Clipboard.GetText(TextDataFormat.Rtf);