`

VSTO excel中插入resource图片

阅读更多

研究VSTO有两个月的时间了,学习到了不少新知识,今天就写一个小内容,如何向excel文件中插入resource里的图片。

 

首先,要在resource里添加一个图片资源,例如 aaa.jpg。 工程名叫 IntsertImage

 

接下来直接上代码:

 

private void insertPic(Excel.Worksheet sheet, Excel.Range picRange)
        {
System.Resources.ResourceManager rs = new System.Resources.ResourceManager("InsertImage.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());
            Object o = rs.GetObject("aaa");
            Bitmap image = (Bitmap)o;
            System.Windows.Forms.Clipboard.SetDataObject(image, true);
            sheet.Paste(picRange, image);
            System.Windows.Forms.Clipboard.Clear();
}

 

方法的参数很好理解,一个是excel的sheet页,一个是想要插入图片的位置。

0
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics