Export to excel in asp.net

Posted by Dipu710646 under Regular Expressions on 12/9/2010 | Points: 10 | Views : 15864 | Status : [Member] | Replies : 7
Hi All,

I am exporting from gridview to excel format. But it is saving as web page. I manually need to save as microsoft excel workbook.Then only it is getting saved as excel. Is there any solution that can be applied to get saved as excel automatically.

Here is the code...

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Resource.xls");
Response.Charset = "";

// If you want the option to open the Excel file without saving then
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());

Please help me..




Responses

Posted by: Chvrsri on: 12/9/2010 [Member] [Moderator] [MVP] Silver | Points: 25

Up
0
Down
In this the actual data from grid would populate in an excel which you could be saved in your harddisk with excel format it self.

After you click a save button it will save in temporary internet folder , with .xls extension as you mentioned this
filename=Resource.xls.

So now what you exactly want?

Thanks,
Radha Srikanth

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dipu710646 on: 12/9/2010 [Member] Starter | Points: 25

Up
0
Down

Thanks for your reply..

Actually it is getting saved as web page not .xls file.

I want that to be saved as .xls file..

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 12/9/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Refer this link using excel workbook...

This link is export to excel in different ways..
http://support.microsoft.com/kb/306023

http://www.eggheadcafe.com/community/aspnet/2/10225917/export-dataset-to-excel-in-windows-applicationwinforms.aspx

Cheers :)

Thanks,
T.Saravanan

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ganeshji on: 12/10/2010 [Member] Starter | Points: 25

Up
0
Down
Try with the following link:
http://www.c-sharpcorner.com/uploadfile/dipalchoksi/exportxl_asp2_dc11032006003657am/exportxl_asp2_dc.aspx


Thnx!
keep posting in dotnetfunda.

Regards,
Ganeshji

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rimi1289 on: 1/30/2013 [Member] Starter | Points: 25

Up
0
Down
Check the below link, it might help you.

http://www.encodedna.com/2013/01/asp.net-export-to-excel.htm

Though the article is slightly different from you requirement, it will definitely help you understand the concept of export data in an Excel sheet.
One more thing. It allows you to export data in latest excel versions also.

You might also be interested in "Importing data from Excel to a database.

http://www.encodedna.com/2013/01/asp.net-import-from-excel.htm



Rimi

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Megan00 on: 1/30/2013 [Member] Starter | Points: 25

Up
0
Down
There are many articles related to export to Excel topic. please see them as below:
http://www.c-sharpcorner.com/UploadFile/83fe73/solutions-to-export-data-from-database-to-excel-in-C-Sharp/
http://excelcsharp.blog.com/2012/10/29/export-excel-to-datatable-and-import-datatable-to-excel/
http://exportdata.codeplex.com/

Never give up! Smile to the world!
http://excelcsharp.blog.com/

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Grdon on: 2/13/2013 [Member] Starter | Points: 25

Up
0
Down
Hello,
You can use a 3rd party libraries to work with Excel files in ASP.NET, for example take a look at this .NET component:
http://www.eleriumsoft.com/Excel_NET/ExcelNET/Default.aspx

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response