Click here to Skip to main content
15,905,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

I am working in Windows Application.I have a form in which I have a gridview,a panel having two picture box of images(LOGOs) and have a button named "EXPORT TO EXCEL".While am clicking the button the Images should place in top level of the excel sheet as heading and below that the gridview details should be there.

So my problem over here is I can export gridview data to excel but cannot export the panel which contain images.To export the gridview details i have added Microsoft.Office.Interop.Excel to Reference and written code in button_click.I am posting the code over here,

C#
Cursor.Current = Cursors.WaitCursor;
           Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
           app.Visible = true;
   Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Add(1);
           Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1];
           ws.Range["a1:o1"].Font.Color = System.Drawing.Color.Red;
           ws.Columns.Font.Bold = true;
           app.Columns.ColumnWidth = 20;
           for (int i = 1; i < dataGridView.Columns.Count + 1; i++)
           {
               app.Cells[1, i] = dataGridView.Columns[i - 1].HeaderText;
           }

           for (int i = 0; i < dataGridView.Rows.Count; i++)
           {
               for (int j = 0; j < dataGridView.Columns.Count; j++)
               {
                   app.Cells[i + 2, j + 1] = Convert.ToString(dataGridView.Rows[i].Cells[j].Value == "" ? "-" : dataGridView.Rows[i].Cells[j].Value);
               }
           }
           Cursor.Current = Cursors.Default;



Please somebody help me to short out this problem.

Thank you.
Posted
Updated 22-Mar-14 4:18am
v2
Comments
Shivani Dash 23-Mar-14 8:57am    
Somebody plz help me...
syed shanu 24-Mar-14 22:13pm    
Chk this http://www.c-sharpcorner.com/uploadfile/suthish_nair/export-image-to-microsoft-office-excel-using-C-Sharp/

http://stackoverflow.com/questions/12122933/inserting-an-image-to-excel-sheet-doesnt-work
syed shanu 24-Mar-14 22:14pm    
Chk this site too http://csharp.net-informations.com/excel/csharp-insert-picture-excel.htm

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