ASP.NET Excel download defaults to HTML with XLS extension

Discussion in 'ASP .Net' started by A B, May 13, 2004.

  1. A B

    A B Guest

    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
     
    A B, May 13, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message news:...
    > 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
     
    Peter O'Reilly, May 13, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PB
    Replies:
    2
    Views:
    2,903
  2. csgraham74

    excel open existing .xls and write dotnet

    csgraham74, Feb 1, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    781
  3. TheVooDooChild
    Replies:
    2
    Views:
    7,691
    gaurav_magic
    Apr 20, 2007
  4. szczepiq
    Replies:
    0
    Views:
    590
    szczepiq
    Jan 16, 2006
  5. Steve
    Replies:
    3
    Views:
    27,000
    Steve
    Aug 25, 2006
Loading...

Share This Page