C# Paste HTML to Excel or PowerPoint

 ̄綄美尐妖づ 提交于 2019-12-11 13:52:22

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/15782784/c-sharp-paste-html-to-excel-or-powerpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!