C# DataGridView`dən excel səhifəyə göndərmə


Datagridview`dən excel səhifəyə göndrəmək üçün bu kodu istifadə edə bilərsiz.Microsoft.Office.Interop.Excel bu kitabxananı proyektinizə əlavə etməyi unutmuyun.


 void excele_gonder(DataGridView dg)
        {
            dg.AllowUserToAddRows = false;
            System.Globalization.CultureInfo dil = System.Threading.Thread.CurrentThread.CurrentCulture;
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-us");
            Microsoft.Office.Interop.Excel.Application cedvel = new Microsoft.Office.Interop.Excel.ApplicationClass();
            Microsoft.Office.Interop.Excel.Workbook kitab = cedvel.Workbooks.Add(true);
       Microsoft.Office.Interop.Excel.Worksheet sehife = (Microsoft.Office.Interop.Excel.Worksheet)cedvel.ActiveSheet;
            System.Threading.Thread.CurrentThread.CurrentCulture = dil;
            cedvel.Visible = true;
            sehife = (Worksheet)kitab.ActiveSheet;
            for (int i = 0; i < dg.Rows.Count; i++)
            {
                for (int j = 0; j < dg.ColumnCount; j++)
                {
                    if (i == 0)
                    {
                        cedvel.Cells[1, j + 1] = dg.Columns[j].HeaderText;
                    }
                    cedvel.Cells[i + 2, j + 1] = dg.Rows[i].Cells[j].Value.ToString();
                }
            }
            cedvel.Visible = true;
            cedvel.UserControl = true;
        } 

Tagged:

Cavab yaz

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: