Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 22nd, 2005, 01:52 AM
Authorized User
 
Join Date: May 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default How DataGrid to Excel 2002 in ASP.NET ?

Hi Friends,

How are you all? Hope you all are doing well.

Now I am doing a project in ASP.NET, with C#. My web page is running on Windows 2000 Professional Server. There I have written a module to download data from DataGrid to an Excel file. The module is as follows.

private void create_excel()
{
    //export to excel
    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);

    DataGridExcel.RenderControl(oHtmlTextWriter);
    Response.Write(oStringWriter.ToString());
    Response.End();
    DataGridExcel.Visible = false;
}

This module is working fine where at the client end OFFICE 2003 is loaded. But this code is not working properly where at the client end OFFICE 2002 is loaded.

The problem is as follows:

1) No save window is appearing before download the excel file.
2) The excel file is opening as a webpage which is not desired.


Hope you all understood the problem. Please help me to solve this problem.

Thanks,

Regards,

Swadhin.
 
Old August 9th, 2006, 06:51 AM
Registered User
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Friend
Actually what you were doing in the code is
You are rendering the Datagrid to HTML Code.
And you are posting the content on to Client browser as Excel file by changing the response headers.

Due to the advance features of Office 2002, it is displayed as HTML for the clients with Office 2002 which is not the case with prior versions of Excel.

To clear your details, you save and open file with notepad, you can find the HTML Content.

If you really want to export the content to Excel, you can do that by using Office web Components installed on the web server.




Regards,
SD





Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2002 Sp1 & Excel Sp2 anup.bihani Excel VBA 0 November 23rd, 2006 04:48 AM
How to Print Datagrid Object in vb.net 2002 kau_shuk VS.NET 2002/2003 0 July 26th, 2006 12:32 PM
Excel 2000 vs Excel 2002 Macro Issue williadn Excel VBA 1 July 14th, 2005 09:09 AM
Excel in win 2000 to excel winxp (excel 2002) Max Excel VBA 3 August 28th, 2003 04:44 AM
Professional ASP.NET 1.0 (2002 Edition) tgoodwin All Other Wrox Books 0 July 15th, 2003 01:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.