【问题标题】:C# VSTO-PowerPoint Copy/Paste Slides with Source FormattingC# VSTO-PowerPoint 复制/粘贴带有源格式的幻灯片
【发布时间】:2012-10-20 08:04:06
【问题描述】:

快速问题希望有人可以在这里提供帮助。我正在尝试将幻灯片从一个 powerpoint 演示文稿复制并粘贴到下一个演示文稿中。我目前有它,以便它将所有数量的幻灯片复制并粘贴到正确的幻灯片上,但我的问题是它只是一遍又一遍地粘贴在演示文稿的最后一张幻灯片上。我已经尝试了 for/foreach 循环,但只是给我一张幻灯片,我想知道它是否不是 CommandBars。但我看到它们被用来在 for/foreach 循环中重置幻灯片。有什么想法吗?

    public void AppendPPTX(string newContent)
    {
        int sourceSlideRange = 0;
        int targetSlideRange = Application.ActiveWindow.Presentation.Slides.Count;
        PowerPoint.Presentation target;
        PowerPoint.Presentation source;

        try
        {
            target = Application.ActivePresentation;
            source = Application.Presentations.Open(newContent, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);

            sourceSlideRange = source.Slides.Count + 1; //otherwise I was just getting the second to the last slide

            for (int i = 1; i < sourceSlideRange; i++)
            {
                source.Slides[i].Copy();
                target.Slides[targetSlideRange].Select();
                target.Application.CommandBars.ExecuteMso("PasteSourceFormatting");
            }
            source.Close();
        }
        catch (Exception)
        {
            MessageBox.Show("Error opening PowerPoint, corruption found inside the powerpoint file. " +
                            Environment.NewLine + "The corrupted file has been deleted." + Environment.NewLine +
                            "Please attempt to redownload file.",
                            "Error Opening PowerPoint",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

    }

【问题讨论】:

    标签: c# vsto powerpoint


    【解决方案1】:

    尝试在 PasteSourceFormatting 之后保存您的 PPT。我确实遇到了同样的问题。

    【讨论】:

    • 感谢您解决了问题。
    【解决方案2】:

    我在PasteSourceFormatting 之后使用了Application.DoEvents(),效果很好!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-17
      • 1970-01-01
      • 2014-10-15
      • 2014-08-29
      • 1970-01-01
      • 2017-09-17
      • 1970-01-01
      • 2020-07-09
      相关资源
      最近更新 更多