Export GridView to Excel (Video)
By AzamSharp
Views: 12588

Introduction:

In this small video tutorial I will show you that how you can export your GridView control to an excel file. I will code the complete application from scratch so that you will have better idea on the exportation procedure.

[Play the video]

I hope you liked the article, happy coding!

 

By AzamSharp


Enter Comment/Feedback
  •  
  •  
  •  
  •  
  •  

Comments/Feedbacks
Subject: Video sessions
Name: sudhakar.koganti
Date: 1/27/2007 1:51:26 AM
Comment:
Hi sir,

your video sessions on grid view topics is excelent.

Iam new developer to the ASP.NET using C#. I want some more video sessions on datagrid, state management, and security issues.

Subject: Excellent
Name: Ira
Date: 2/1/2007 11:50:23 AM
Comment:
Very clear, precise and a wonderful presentation. Excellent job!
Subject: Minor Correction
Name: KarlR
Date: 2/2/2007 12:38:11 PM
Comment:
As mentioned below, this is an outstanding tutorial video. I wish I had run into this earlier.

However, when I was running into that "RegisterForEventValidation" error, I had to change the EnableEventValidation=False instead of the ValidateRequest=False (as explained in the video).
I just wanted to post this in case someone had a similar problem.
Thanks again!
Subject: More Video Tutorials on GridViewGuy Videos
Name: AzamSharp
Date: 2/2/2007 2:13:35 PM
Comment:
Hi,

You can find several other video tutorials on www.videos.gridviewguy.com. You will need to buy the subscription which only cost $10.00 dollars for life time subscription.

Visit: www.videos.gridviewguy.com

New tutorials are added each week.
Subject: Gridview export to excel
Name: Leander Šeško
Date: 2/17/2007 11:46:23 PM
Comment:
I like your videos and other examples very much.

Please explain how to set the path where the excel file should be saved in the code behind.

Is there possible to save excel without asking the user and just put the message that file is saved?

Best regards
Subject: Video for Exporting to Excel
Name: Karthik
Date: 3/30/2007 11:49:15 PM
Comment:
Great video, helped me a lot. Thanks, post more such general videos like this one.
Subject: Error on HtmlTextWriter
Name: Jim
Date: 4/11/2007 9:01:44 AM
Comment:
Following your instructions in the video, I recieved this error:

No overload for method 'HtmlTextWriter' takes '0' arguments.

On this line of your button click event.

HtmlTextWriter htw = new HtmlTextWriter();
Subject: Good Work
Name: Tamil
Date: 4/12/2007 2:57:53 AM
Comment:
Hello AzamSharp,

Good work

Making things from the scratch will be easy for newbie to pick up the concept.

write more articles

Cheers,
Tamil
Subject: RE: Good Work
Name: AzamSharp
Date: 4/12/2007 1:00:37 PM
Comment:
Hi,

Thanks for the feedback. You can watch more videos at www.videos.gridviewguy.com.

Subject: RE: HtmlTextWriter
Name: AzamSharp
Date: 4/12/2007 1:04:51 PM
Comment:
Hi,

You can feed StringWriter into the HtmlTextWriter constructor.
Subject: Excel Viewer
Name: Joe
Date: 4/16/2007 10:05:27 AM
Comment:
I've implement this solution and the file works fine if you open with Excel. However, people using the Excel Viewer cannot.


Is there a easy fix for this?
Thanks
Joe
Subject: export to excel
Name: Evangeline
Date: 5/22/2007 9:39:45 PM
Comment:
Hi

I really enjoyed watching this clip as it gave me a clearer picture as to how to export, however I use vb.net and was wondering how to write that last line of code in vb(override bit)

thanks
Subject: It helped
Name: vish
Date: 6/27/2007 4:39:02 PM
Comment:
Hey,
the video on gridview to excel helped.

One tip was, whenever I tried to dynamically get file name from user and if it was empty, thats when the whole aspex was rendered. Otherwise the excel has been renderig tilldate. thanks
Subject: Override in VB
Name: Mary
Date: 7/18/2007 4:53:08 AM
Comment:
Public Overrides Sub VerifyRenderingInServerForm(ByVal Control As Web.UI.Control)
End Sub
Subject: RE: Override in VB
Name: AzamSharp
Date: 7/19/2007 7:54:57 AM
Comment:
Hi Mary,

Thanks for providing the code in VB!
Subject: Save directly to server hard drive
Name: Moura
Date: 8/6/2007 6:46:48 AM
Comment:
how can I save the xls file directly on server's hard drive without confirmation?

best regards
moura
Subject: How to set path???
Name: julie
Date: 10/4/2007 12:41:05 AM
Comment:
Can you Please explain how to set the path where the excel file should be saved .

I need to save excel without asking the user.
Itz very urgent. Can u plz help me out in this.
Subject: RE: How to set path???
Name: AzamSharp
Date: 10/7/2007 9:17:00 AM
Comment:
Hi Julie,

You cannot set path to where to save the Excel file on the client machine. This is the responsibility of the client.
Subject: GV Export to Excel
Name: Maria
Date: 1/21/2008 11:56:09 AM
Comment:
Question:
My gridview export to Excel works fine. However, I have a long numerical field that doesn't export correctly . When exporting data from a gridview to Excel, large numbers get converted to x.xxxE-yy syntax. How do I get around this? I have 7 columns to export and only column 5 is numerical and has this behavior.

I need a VB solution and can’t find anything. I’ve seen similar solutions in C# and have tried to implement with no luck. I’m sure this is commonplace.

Thoughts/ideas/suggestions??? Anything would be a great help.
Subject: export data 2 excelsheet
Name: naresh
Date: 2/5/2008 4:59:43 AM
Comment:
excellent
Subject: cells are not visible
Name: Om Kumar
Date: 3/21/2008 10:44:26 AM
Comment:
HI Sir,
your work is excellint, but I Have one doubt that is when the data is storing in the excel the cells are not appearing even in want to display the cell and if the content is more it is displaying in xxxx format please send me a proper solution.
thanks again
Subject: Problem with export to Excel
Name: Ashutosh Kumar
Date: 3/26/2008 11:07:29 PM
Comment:
I saw the video . its really very good and useful . i have some query , i want to export only one or two column in excel. please reply me as soon as possible.

Regards
Ashutosh
Subject: How to export with Syles Sheet
Name: Priya
Date: 4/11/2008 9:34:15 AM
Comment:
I have modifed the code so that it could be a more of common function
and instead of overriding the mothod I have added form

// Create a form to contain the grid

HtmlForm frm = new HtmlForm();
grdView.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(grdView);
frm.RenderControl(htw);
//GridView1.RenderControl(htw);
System.Web.HttpContext.Current.Response.Write(sw.ToString());
System.Web.HttpContext.Current.Response.End();

Everything works fine only the syle sheet is not exported
Can we fix this
Thanks
Subject: Export data to Ecel from Gridview Control
Name: sindhura
Date: 4/22/2008 9:39:18 PM
Comment:
Really good and helpful.
Subject: the webpage loses focus after exporting to excel
Name: Sita
Date: 7/1/2008 12:23:42 PM
Comment:
It is a great video. Thanks. My problem is that I have a webpage where I have couple more buttons apart from the exportToExcel button. When I'm done saving the excel file and closing the file, can I come back to my webform and have focus on the webpage?

Please let me know.

Thanks,
Sita.
Subject: re: the webpage loses focus after exporting to excel
Name: AzamSharp
Date: 7/5/2008 9:27:11 AM
Comment:
Hi Sita,

I am not what you meant by having focus on the webform when you come to the webpage?




Join WebHost4Life.com






Copyright GridViewGuy 2007-2008