Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ı want to send a picture in a picturebox to excel cell for exmp:excel.cells[10,10]

is there possible?
Posted
Comments
S Houghtelin 24-May-11 8:20am    
Yes it is possible.

Where is the picturebox? (A form in excel?, another spreadsheet? an application outside of Excel?)

More information would be helpful for others to help.

Regards.
wellcometoend 24-May-11 8:37am    
APPLİCATİON OUTSİDE OF EXCEL

there is a windows form and picture come to a picturebox if ı click print button all information about this guy and this guy picture must go to excel.I did a excel template. Picture must go cell[10,10]in excel.
wellcometoend 24-May-11 8:39am    
this is my print button has include like this code

MExcel.Application Exceluygulama = new MExcel.Application();
MExcel.Workbook Excelkitap = Exceluygulama.Workbooks.Add(Application.StartupPath + "\\Rapor\\ogrencibelgesi.xls");
MExcel.Worksheet Excelsayfa = (MExcel.Worksheet)Exceluygulama.ActiveSheet;
Exceluygulama.Visible = true;
Exceluygulama.Cells[5, 5] = comboBox1.Text;
Exceluygulama.Cells[8, 10] = DateTime.Now.ToShortDateString();
Exceluygulama.Cells[16, 4] = textBox6.Text;

1 solution

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.

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


Inside your clickevent:

C#
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.
              
            }
        }


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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900