Vb.net 使用.NET的Spire.Presentation从pptx中的组形状中提取文本

Vb.net 使用.NET的Spire.Presentation从pptx中的组形状中提取文本,vb.net,Vb.net,我正在尝试使用Spire.presentation插件从power point演示文稿中获取文本。我能够用下面的代码成功地从简单的文本框中提取文本。但一旦文本框组合在一起,代码就会返回空行。当形状分组时,请帮助获取文本。在任何地方都找不到任何解决方案 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim presentation As New Presentation("

我正在尝试使用Spire.presentation插件从power point演示文稿中获取文本。我能够用下面的代码成功地从简单的文本框中提取文本。但一旦文本框组合在一起,代码就会返回空行。当形状分组时,请帮助获取文本。在任何地方都找不到任何解决方案

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim presentation As New Presentation("Drawing.pptx", FileFormat.Pptx2010)
    Dim sb As New StringBuilder()
    For Each slide As ISlide In presentation.Slides
        For Each shape As IShape In slide.Shapes
            If TypeOf shape Is IAutoShape Then
                For Each tp As TextParagraph In TryCast(shape, IAutoShape).TextFrame.Paragraphs
                    sb.Append(tp.Text + Environment.NewLine)
                Next
            End If

        Next
    Next
    File.WriteAllText("target.txt", sb.ToString())
    Process.Start("target.txt")

End Sub

可以使用以下代码从形状和编组形状中提取文本。代码是用c#编写的,但我认为您可以将其传输到vb.net

Presentation ppt = new Presentation(@"..\..\test document\3SlidesNoTransitions8762.pptx", FileFormat.Pptx2010);
        StringBuilder sb = new StringBuilder();
        foreach (ISlide slide in ppt.Slides)
        {
            foreach (IShape shape in slide.Shapes)
            {
                sb.AppendLine(getShapeText(shape));
            }
            File.WriteAllText("8672.txt", sb.ToString());
        }
    }
    public static string getShapeText(IShape shape)
    {
        StringBuilder sb = new StringBuilder();
        if (shape is IAutoShape)
        {
            IAutoShape ashape = shape as IAutoShape;
            if (ashape.TextFrame != null)
            {
                foreach (TextParagraph pg in ashape.TextFrame.Paragraphs)
                {
                    sb.AppendLine(pg.Text);
                }
            }
        }
        else if (shape is GroupShape)
        {
            GroupShape gs = shape as GroupShape;
            foreach (IShape s in gs.Shapes)
            {
                sb.AppendLine(getShapeText(s));
            }
        }
        return sb.ToString();
    }

关闭我认为这个问题没有一个简单的答案。因此,我切换到PHP并以期望的格式提取所需的文本,发现PHP比VB.NET更容易和更复杂地完成这个简单的任务。谢谢Dheeraj,当我再次需要桌面应用程序时,我会考虑您的解决方案,但是有一个时间限制,所以我已经通过PHP完成了它。