By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,263 Members | 1,574 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,263 IT Pros & Developers. It's quick & easy.

Exporting Datagrid's data to an Excel Sheet.

P: n/a
I have a web form in which I have a datagrid, I need to export this data to
a Microsoft Excel sheet.

I'm doing it thus:

Response.Clear();

Response.Buffer= true;

Response.ContentType = "application/vnd.ms-excel";

Response.Charset = "";

this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);

DataGrid1.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());

Response.End();

But I'd like to avoid system ask user if desires open or save this file,
instead would open excel sheet as another window and when user saves the
file it be saved as an excel file.

Does somebody knows how achieve this?

I'll appreciate it very much.

A.L.

--
see07 - forum member
http://www.visual-basic-data-mining.net/forum
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
This article provides a good example for you:
http://www.aspnetpro.com/NewsletterA...200309so_l.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"http://www.visual-basic-data-mining.net/forum" <si******@gmail.com> wrote
in message news:ub**************@TK2MSFTNGP11.phx.gbl...
I have a web form in which I have a datagrid, I need to export this data to
a Microsoft Excel sheet.

I'm doing it thus:

Response.Clear();

Response.Buffer= true;

Response.ContentType = "application/vnd.ms-excel";

Response.Charset = "";

this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);

DataGrid1.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());

Response.End();

But I'd like to avoid system ask user if desires open or save this file,
instead would open excel sheet as another window and when user saves the
file it be saved as an excel file.

Does somebody knows how achieve this?

I'll appreciate it very much.

A.L.

--
see07 - forum member
http://www.visual-basic-data-mining.net/forum

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.