473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

ASP.NET Excel download defaults to HTML with XLS extension

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
1 4176
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jim | last post by:
I'm trying to stream a html page to the user as an excel file. I'm currently using Response.ContentType = "application/vnd.ms-excel" Response.AddHeader "Content-Disposition", "inline;...
11
by: James Baker | last post by:
Here's my situation. I need on-site manager's to be able to view a list of records on our website (which they already can do). They need to be able to select any/all fields and then export...
0
by: Pankaj Garg | last post by:
I have written a program, where I download reports in PDF or Excel format, depends on user selection. My code is working fine for PDF format, but same code os not working for excel file. When I...
1
by: hunt n peck | last post by:
I want to provide the user with the ability to perform a search, fine-tune the search results, and then download the results in Excel format. The desired effect: 1- user enters search...
4
by: Jae | last post by:
I'm writing a web application that exports and imports excel files. The application gets a list of users and their info and displays it in a datagrid .The user then selects to save the file as a...
0
by: Ron Vecchi | last post by:
Hello, Through using this and many other Microsoft dotnet newsgroups I have been pointed towards many helpful open source projects and articles that have helped a great deal in my studies as...
4
by: JaxDawg | last post by:
I have a spreadsheet saved as an XML spreadsheet so I can manipulate it easier (and don't need COM). When I'm done, I want to display to the user. Currently, I'm using simple JavaScript in my PHP...
6
by: Eddie | last post by:
Hi all, I am displaying a number of reports, and giving the users an option to display them on the web or download them to Excel. If they want the Excel file, I just use the PHP header command...
5
by: Doogie | last post by:
Can anoyne tell me why this VBScript will create the file to Excel just fine, but the Excel file will not open up? I am saving it as a xlsx file instead of an xls one and I have the new version of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.