Export To Excel - ASP.NET 1.1

J

JawzX01

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.NoCache);

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
 
A

Alvin Bruney [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top