C#将HTML粘贴到Excel或PowerPoint [英] C# Paste HTML to Excel or PowerPoint

查看:163
本文介绍了C#将HTML粘贴到Excel或PowerPoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将HTML(表)代码粘贴到Excel或PowerPoint中?

解决方案

我已经克服了有关粘贴HTML进入Excel和PowerPoint,并注意到很多人都在问这个问题。



我想分享我的研究,我为之作出的解决方案。

假设我们有一个名为 html 的html文件,我们希望在Excel中访问它,让我们进行以下操作:

  Clipboard.SetText(html); 

将我们的 html 复制到剪贴板中。剪贴板从html输入一个真实的表格或图像/图表从输入文件生成。

  System.Threading.Thread.Sleep 2000年); 

让我们等一下预览

  sheet.Range(cellmapp).PasteSpecial(); 

现在,我们将内容粘贴到我们希望粘贴的范围内,定义 cellmap

  System.Threading.Thread.Sleep(1000); 

让我们等一下看看输出

  sheet.UsedRange.Copy(Missing.Value); 

现在,为了将表格映像复制到PowerPoint中,我们必须使用 UsedRange .Copy ,因为它将复制当前选择的Excel区域。



为了检查我们将其粘贴到正确的Powerpoint幻灯片中

  foreach(PowerPoint.Slide slide in presentation.Slides)
{
foreach(PowerPoint.Shape pptshape in slide.Shapes)
{
if(<您的条件满足>)
{
slide.Select(); //任何幻灯片中的某个位置
pptshape.Delete(); //删除该幻灯片中的旧内容
ppApp.ActiveWindow.View.PasteSpecial(); //粘贴Excel内容
}
}
}

当然还有其他的解决方案,比如使用html代码制作图像,粘贴,这是我的初步想法。



另一篇文章涉及到操作:
在PowerPoint中显示HTML


How to paste HTML ( tables ) code into Excel or PowerPoint?

解决方案

I've overcome some issues concerning pasting HTML into Excel and PowerPoint and noticed that a lot of people are asking that.

I'd like to share my research, solution I made out for it.

Let's say we have a html file named html and we would like to access it in Excel, let's do following:

Clipboard.SetText(html);

We copy our html into the Clipboard. The clipboard generates from the html a real table or image/chart from the input file.

System.Threading.Thread.Sleep(2000);

Let's wait a second to have a preview

sheet.Range(cellmapp).PasteSpecial();   

Now, we paste the content into a range that we could like to paste it, by defining cellmap.

System.Threading.Thread.Sleep(1000);

Let's wait a second to see the output

sheet.UsedRange.Copy(Missing.Value);

Now, in order to copy the table image into PowerPoint, we must work the with UsedRange.Copy, because it will copy the currently selected Excel area.

In order to check that we paste it into the correct Powerpoint slide

foreach (PowerPoint.Slide slide in presentation.Slides)
{
    foreach (PowerPoint.Shape pptshape in slide.Shapes)
    {
        if(<your condition satisfies>)
        {
            slide.Select(); // some position in any slide
            pptshape.Delete();//delete old content that was in that slide
            ppApp.ActiveWindow.View.PasteSpecial(); //paste the Excel content
        }
    }
}

Of course there are other solutions, like making an image out of the html code and pasting that, which was my initial idea.

Another post refering that manipulation: Showing HTML in PowerPoint

这篇关于C#将HTML粘贴到Excel或PowerPoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆