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

Export To Excel - ASP.NET 1.1

P: n/a
Hello All,
First, thank you for any help you can provide.

I'm trying to do a simple export to excel. I've used the classic
code that is all over the internet, and of course it worked without a
problem.

The problem is that I want to add text above the data grid in the
excel sheet. The text already exists on the web page in various panels
(there is different text depending on the parameters of the datagrid
report). But, every attempt to accomplish this, results in HTML being
rendered (for both the text and the data grid). Again, the data grid
exports correctly without the additional text.
Any help would be appreciated, even a references to an article on the
internet.
--- The code I'm using --
//Filling the data grid is handled else where...

//
//export to excel
Response.Clear();

Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.No Cache);

Response.ContentType = "application/vnd.ms-excel";
//Response.ContentType = "application/vnd.xls";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new
System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);

dgReport.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
----
Here are a couple things that I've tried. Just before the
dgReport.RenderControl(oHtmlTextWriter), I've inserted
rptText.RenderControl(oHtmlTextWriter) -- this "worked" but the HTML
formating didn't work, all of the HTML was visible in excel like I was
looking at the page in notepad.

Additionally, I've tried to export the entire page to excel, but then
the headers (and filter bar) show up in it. My attempt to hide all of
the headers (and the filter bar) didn't work... Even though the
visible property (wrapped around the filter bar) was set to false, it
still rendered in excel.

I hope this is enough information, but if more is needed ask.

Thank you & Regards,
Frank

Mar 15 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
The method you are using converts the contenttype of the entire page which
works well for display excel but leaves very little room for customization.
Perhaps add a header data row with the required information before streaming
out the input. It's not as neat but it should provide a workaround.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"JawzX01" <ja*****@gmail.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
Hello All,
First, thank you for any help you can provide.

I'm trying to do a simple export to excel. I've used the classic
code that is all over the internet, and of course it worked without a
problem.

The problem is that I want to add text above the data grid in the
excel sheet. The text already exists on the web page in various panels
(there is different text depending on the parameters of the datagrid
report). But, every attempt to accomplish this, results in HTML being
rendered (for both the text and the data grid). Again, the data grid
exports correctly without the additional text.
Any help would be appreciated, even a references to an article on the
internet.
--- The code I'm using --
//Filling the data grid is handled else where...

//
//export to excel
Response.Clear();

Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.No Cache);

Response.ContentType = "application/vnd.ms-excel";
//Response.ContentType = "application/vnd.xls";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new
System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);

dgReport.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
----
Here are a couple things that I've tried. Just before the
dgReport.RenderControl(oHtmlTextWriter), I've inserted
rptText.RenderControl(oHtmlTextWriter) -- this "worked" but the HTML
formating didn't work, all of the HTML was visible in excel like I was
looking at the page in notepad.

Additionally, I've tried to export the entire page to excel, but then
the headers (and filter bar) show up in it. My attempt to hide all of
the headers (and the filter bar) didn't work... Even though the
visible property (wrapped around the filter bar) was set to false, it
still rendered in excel.

I hope this is enough information, but if more is needed ask.

Thank you & Regards,
Frank

Mar 18 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.