By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,454 Members | 1,803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,454 IT Pros & Developers. It's quick & easy.

ASP.NET Excel download defaults to HTML with XLS extension

P: n/a
A B
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
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <ab@example.org> wrote in message news:2g************@uni-berlin.de...
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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.