【问题标题】:Copying a range of cells from excel into powerpoint using VSTO使用 VSTO 将一系列单元格从 excel 复制到 powerpoint
【发布时间】:2010-07-12 13:17:57
【问题描述】:

如何将一系列单元格从 Excel 复制到 Powerpoint。当您选择一系列单元格,复制到剪贴板,然后粘贴到幻灯片中时,我想做同样的事情。

我已经尝试过Range.Copy(missing)Slide.Shapes.Paste 这段代码,但它不起作用。它会引发类似

的异常

'Shapes(未知成员):无效请求。剪贴板为空或 包含可能不会在此处粘贴的数据。'

剪贴板确实包含数据,但谷歌搜索错误表明其他人也面临着我正在使用的 Excel 2007 的这个问题。

我的代码如下所示:

PowerPoint.ApplicationClass app = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
app.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
PowerPoint.Presentation pptPresentation = app.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);

Excel.Worksheet NewWorksheet = ThisApplication.Sheets[i] as Excel.Worksheet;
// Add a blank slide to the presentation.
PowerPoint.Slide pptSlide = pptPresentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank);
pptSlide.Name = NewWorksheet.Name;

Excel.Range resultRange = NewWorksheet.UsedRange;
resultRange.Copy(missing); 
pptSlide.Shapes.Paste();

现在我正在逐个遍历 excel 工作表的单元格,在 powerpoint 中创建一个包含正确行和列的表格并粘贴,但速度很慢,我必须通过更改字体来将数据放入幻灯片中大小,而这是在粘贴整个范围时通过 powerpoint 完成的。

如何在不遍历每个单元格的情况下复制整个范围?

有什么建议吗?

【问题讨论】:

    标签: c# excel vsto


    【解决方案1】:

    如果你使用会发生什么:

    app.ActiveWindow.View.Paste(); 
    // instead of
    // pptSlide.Shapes.Paste();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-02
      • 2011-04-19
      • 2014-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多