如何在图片框内发送图片以达到卓越效果? [英] how to send a picture in a picturebox to excel?

查看:76
本文介绍了如何在图片框内发送图片以达到卓越效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ı想要将图片框中的图片发送到excel单元格以用于exmp:excel.cells [10,10]

ı want to send a picture in a picturebox to excel cell for exmp:excel.cells[10,10]

is there possible?

推荐答案

在项目"菜单的添加引用"下添加对Excel的引用.在"COM"选项卡下,选择要使用的版本的Excel.

将以下两行添加到表单代码顶部的指令中.

Add a reference to Excel under Project menu Add Reference. Under the COM tab and select Excel of the version to be used.

Add the following two lines to the directive at the top of the form code.

using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;



在您的clickevent中:



Inside your clickevent:

private void button1_Click(object sender, EventArgs e)
        {
            Excel.Application Exceluygulama;
            Excel.Workbook Excelkitap;
            Excel.Worksheet Excelsayfa;
            try
            {
                // Start Excel
                Exceluygulama = new Excel.Application();
                Exceluygulama.Visible = true;
                //Create workbook.
                Excelkitap = (Excel.Workbook)(Exceluygulama.Workbooks.Add(Missing.Value));
                Excelsayfa = (Excel.Worksheet)Excelkitap.ActiveSheet;
                //Get and display image in picture object
                Excelsayfa.Shapes.AddPicture("C:\\MyPic.Bmp", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 425, 130, 100, 125);

                // ...And so forth
                Exceluygulama.Cells[5, 5] = "Text Item 1";
                Exceluygulama.Cells[8, 10] = DateTime.Now.ToShortDateString();
                Exceluygulama.Cells[16, 4] = "Text Item 2";
            }
            catch // Do something in case there is an error
            {     // such as Excel not installed.
              
            }
        }



AddPicture末尾的数字是图片的左侧,顶部,宽度和高度.您需要确定图片的大小和位置,以便可以将图片放置在Cell(10,10)的位置上.

这里有更多信息: http://support.microsoft.com/kb/302084 [



The numbers at the end of the AddPicture are the Left, Top, Width and Height of the picture. You will need to size and locate he picture so that you can place the picture over the Cell(10,10) location.

There is more information here: http://support.microsoft.com/kb/302084[^]

You should be able to navigate the workbook, copy paste etc. using cell referencing.

Regards.


这篇关于如何在图片框内发送图片以达到卓越效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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