Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP.NET Excel download defaults to HTML with XLS extension

Reply
Thread Tools

ASP.NET Excel download defaults to HTML with XLS extension

 
 
A B
Guest
Posts: n/a
 
      05-13-2004
Hello,

I have the following two lines in my VB.NET code to cause a datagrid to
output in Excel format:

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-disposition","attachment;filename=HubXLOut.xls")

When I click the "Open" dialog box and then Save As ->, the default file
type selected is HTML, not XLS. The file is appropriately named
HubXLOut.xls, however. If I do not change the dropdown to Microsoft
Excel before the save, my .NET application is unable to read this file
using OLEDB. Also, if I click "Save" on the initial dialog box, the
file is saved with an XLS extension, but OLEDB cannot read the file as
an Excel file. I don't want our customers to have to go through the
extra steps of Save As -> and then having to change the dropdown to
Excel. Any suggestions?

Thanks!

AB
 
Reply With Quote
 
 
 
 
Peter O'Reilly
Guest
Posts: n/a
 
      05-13-2004
Your ASP.NET application streams the file as HTML.
Excel takes that stream and interprets in a way that it can present on the
spreadsheet, but it is still HTML content.
There's an OLEDB extension for XLS binary files, but not for HTML formatted
text.

Before your .NET application reads the file, it shoudl detect if it's a
binary or a text format.
If it's binary then either
-use (OLE) Automation to manipulate an instance of Excel to open the file,
save it as XLS and then close it
or
- use the Excel SDK available from MSDN (if it still exists) to do the file
format conversion.

The first option is much easier to implement than the second.

Good luck
--
Peter O'Reilly
"A B" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> Hello,
>
> I have the following two lines in my VB.NET code to cause a datagrid to
> output in Excel format:
>
> Response.ContentType = "application/vnd.ms-excel"
>

Response.AddHeader("Content-disposition","attachment;filename=HubXLOut.xls")
>
> When I click the "Open" dialog box and then Save As ->, the default file
> type selected is HTML, not XLS. The file is appropriately named
> HubXLOut.xls, however. If I do not change the dropdown to Microsoft
> Excel before the save, my .NET application is unable to read this file
> using OLEDB. Also, if I click "Save" on the initial dialog box, the
> file is saved with an XLS extension, but OLEDB cannot read the file as
> an Excel file. I don't want our customers to have to go through the
> extra steps of Save As -> and then having to change the dropdown to
> Excel. Any suggestions?
>
> Thanks!
>
> AB



 
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
PL/SQL to transfer data from Excel .xls to Oracle Table TheVooDooChild Java 2 04-20-2007 05:05 AM
How to convert a .txt file extension to a .xls file extension? Steve ASP .Net 3 08-25-2006 05:43 PM
excel open existing .xls and write dotnet csgraham74 ASP .Net 3 02-02-2006 06:25 PM
Excel (.xls) to .xml conversion. Pravin C++ 1 04-18-2005 11:17 AM
Restoring Download Defaults in IE 6 Sens Fan Happy In Florida Computer Support 2 10-12-2003 11:56 PM



Advertisments