如何将图像从Winform导出到Excel [英] How to export image from Winform to Excel

查看:389
本文介绍了如何将图像从Winform导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我在Windows Application中工作。我有一个表单,其中我有一个gridview,一个面板有两个图片框图像(LOGO)并且有一个名为EXPORT TO EXCEL的按钮。当点击按钮时,图像应该放在excel表的顶层作为标题,并且在gridview的详细信息应该在那里。



所以我的问题是我可以将gridview数据导出到excel但是无法导出包含images的面板。要导出gridview的详细信息,我已将Microsoft.Office.Interop.Excel添加到reference并在button_click中编写代码我在这里发布代码,



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,

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.

推荐答案

这篇关于如何将图像从Winform导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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