Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Export to Excel C#

Reply
Thread Tools

Export to Excel C#

 
 
Ugo
Guest
Posts: n/a
 
      06-04-2004
Hi,
I am having a problem exporting a Datagrid to excel in asp.net. For
some reason I am getting a blank excel page. I set up in IIS the Mime for
..xls. My code is below any help would be appreciated..

Thanks

CODE:

private void ExportToExcel()
{
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.Charset = "";
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
DataGrid dg = new DataGrid();
dg.DataSource = (DataSet) Cache["dataset"];
dg.DataBind();
dg.RenderControl(hw);
Response.Write(tw.ToString());
Response.Flush() ;
Response.Close();
}


 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      06-04-2004
You might want to compare your code to the sample here to see what is
different about your approach:

HOW TO: Export Data in a DataGrid on an ASP . NET WebForm to Microsoft Excel

http://support.microsoft.com/default...b;en-us;317719

"Ugo" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
> I am having a problem exporting a Datagrid to excel in asp.net.
> For
> some reason I am getting a blank excel page. I set up in IIS the Mime for
> .xls. My code is below any help would be appreciated..
>
> Thanks
>
> CODE:
>
> private void ExportToExcel()
> {
> Response.Clear();
> Response.ContentType = "application/vnd.ms-excel";
> Response.ContentEncoding = System.Text.Encoding.Default;
> Response.Charset = "";
> this.EnableViewState = false;
> StringWriter tw = new StringWriter();
> HtmlTextWriter hw = new HtmlTextWriter(tw);
> DataGrid dg = new DataGrid();
> dg.DataSource = (DataSet) Cache["dataset"];
> dg.DataBind();
> dg.RenderControl(hw);
> Response.Write(tw.ToString());
> Response.Flush() ;
> Response.Close();
> }
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export to Excel (Default File Type - Excel) =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?= ASP .Net 15 05-21-2009 12:01 PM
Problem with Excel reports ::::Excel 2003 Migration To Excel 2007 =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?= ASP .Net 15 10-24-2007 01:34 PM
Export to excel in asp.net using excel template Grey ASP .Net 4 10-17-2007 08:08 AM
using Microsoft Excel image for Export to Excel button =?Utf-8?B?U3JpZGhhcg==?= ASP .Net 0 12-09-2005 08:58 PM
Invalid export DLL or export format =?Utf-8?B?RGF2aWQgVmFsbGU=?= ASP .Net 0 10-29-2003 11:46 AM



Advertisments