Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

I would like to put spaces in the datagridview as well as different from the image.I putt into excel.

$
0
0
private void button5_Click(object sender, EventArgs e)
        {
            {
                Microsoft.Office.Interop.Excel.Application uyg = new Microsoft.Office.Interop.Excel.Application();
                uyg.Visible = true;
                Microsoft.Office.Interop.Excel.Workbook kitap = uyg.Workbooks.Add(System.Reflection.Missing.Value);
                Microsoft.Office.Interop.Excel.Worksheet sheet1 = (Microsoft.Office.Interop.Excel.Worksheet)kitap.Sheets[1];
                Microsoft.Office.Interop.Excel.Range myRange;
                for (int i = 0; i < dataGridView1.Columns.Count; i++)
                {
                    myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[1, i + 1];
                    myRange.Value2 = dataGridView1.Columns[i].HeaderText;
                    for (int j = 0; j < dataGridView1.Rows.Count; j++)
                    {
                        myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[j + 2, i + 1];
                        if (dataGridView1[i, j].GetType() == typeof(DataGridViewImageCell))
                        {
                            byte[] bimage = (byte[])(new ImageConverter().ConvertTo(dataGridView1[i, j].Value, typeof(byte[])));
                            MemoryStream ms = new MemoryStream(bimage);
                            Image image = Image.FromStream(ms);
                            image.Save(@"D:\dosya.jpg");
                            float Left = (float)(myRange.Left);
                            float Top = (float)(myRange.Top);
                            const float ImageSize = 32;
                            sheet1.Shapes.AddPicture(@"D:\dosya.jpg", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, Left, Top, ImageSize, ImageSize);
                            myRange.RowHeight = ImageSize + 2;
                            File.Delete(@"D:\dosya.jpg");
                            
                        }
                        else
                            myRange.Value2 = dataGridView1[i, j].Value;
                    }
                }
            }
        }

Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>