Click here to Skip to main content
15,905,877 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Export GridData in Excel Sheet in Vertical Format in C# asp.net Plz help
Posted
Comments
Prerak Patel 15-Jul-11 2:56am    
Elaborate more.
R. Giskard Reventlov 15-Jul-11 3:31am    
Try asking a proper question. Besides, what have you already tried for yourself?

1 solution

Try This method,It works properly.
C#
<pre lang="cs">public void export_datagridview_to_excel(System.Windows.Forms.DataGridView dgv, string excel_file)
        {
            int cols;
            //open file
            StreamWriter wr = new StreamWriter(excel_file);

            //determine the number of columns and write columns to file
            cols = dgv.Columns.Count;
//write to excel
            for (int i = 0; i < cols; i++)
            {
                wr.Write(dgv.Columns[i].HeaderText.ToString() + "\t");
                wr.Write("\t");
                wr.Write(dgv.Rows[0].Cells[i].Value + "\r\n");
            }
            wr.Close();

        }

 
Share this answer
 
Comments
sk saini 16-Jul-11 6:51am    
Working properly.

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