471,897 Members | 1,291 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,897 software developers and data experts.

Export To Excel - ASP.NET 1.1

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
1 7104
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.

Similar topics

1 post views Thread by san1014 | last post: by
reply views Thread by Dubois | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.