Export Datagrid to Excel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a dataset which I bind to a datagrid on my ASPX.

I then export the datagrid to Excel and stream the file to the user by
setting the MIME Type etc etc.



Response.ContentType = "application/vnd.ms-excel";

Response.AddHeader("content-disposition", "attachment;filename=MyFile.xls");

However, the problem I have is that it streams it as an Excel Worksheet.

When the user clicks on Save they get "Excel WorkSheet" or "HTML Page" as
the File Types.

I need to stream this as a workbook.

Has anyone else had the same problem.

Any advice or help is much appreciated.

Thanks,
C.
 
To get a workbook you would need to use a 3rd party control such as
softartisans excel writer or the office web components from microsoft.

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc
 
What happens if you don't tell the browser that it is an Excel file?

Response.ContentType = "application/octet-stream";
Response.Flush();
 
Back
Top