Exporting to Excel using new version of Excel

Discussion in 'ASP .Net' started by Doogie, Nov 19, 2008.

  1. Doogie

    Doogie Guest

    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 Excel on
    my machine and have opened other Excel files with that extension but
    this one I get the following error:

    "Excel cannot open the file 'Test.xlsx' because the file format or
    file extension is not valid. Verify that the file has not been
    corrupted and the file extension matches the format of the file."

    If I switch the file type to be .xls instead of .xlsx, it will save
    the file and open with no problems. Below is an example of the VB
    script I'm using.

    dim Cn,Rs
    set Cn=server.createobject("ADODB.connection")
    set Rs=server.createobject("ADODB.recordset")
    Cn.open "MyConnectionString"
    Rs.open "mysqlquery",Cn,1,3
    Response.ContentType = "application/vnd.ms-excel"
    Response.AddHeader "Content-Disposition", "attachment;
    filename=Test.xlsx"
    if Rs.eof <> true then
    response.write "<table border=1>"
    while not Rs.eof
    response.write "<tr><td>" & Rs.fields("mydatafield") & "</
    td></tr>"
    Rs.movenext
    wend

    response.write "</table>"
    end if

    set rs=nothing
    Cn.close
    Doogie, Nov 19, 2008
    #1
    1. Advertising

  2. Doogie

    sloan Guest

    This is a newsgroup for asp.NET , not "classic" asp.

    ..........

    You'll find better luck in another newsgroup.

    Maybe this one:
    microsoft.public.inetserver.asp.general




    "Doogie" <> wrote in message
    news:...
    > 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 Excel on
    > my machine and have opened other Excel files with that extension but
    > this one I get the following error:
    >
    > "Excel cannot open the file 'Test.xlsx' because the file format or
    > file extension is not valid. Verify that the file has not been
    > corrupted and the file extension matches the format of the file."
    >
    > If I switch the file type to be .xls instead of .xlsx, it will save
    > the file and open with no problems. Below is an example of the VB
    > script I'm using.
    >
    > dim Cn,Rs
    > set Cn=server.createobject("ADODB.connection")
    > set Rs=server.createobject("ADODB.recordset")
    > Cn.open "MyConnectionString"
    > Rs.open "mysqlquery",Cn,1,3
    > Response.ContentType = "application/vnd.ms-excel"
    > Response.AddHeader "Content-Disposition", "attachment;
    > filename=Test.xlsx"
    > if Rs.eof <> true then
    > response.write "<table border=1>"
    > while not Rs.eof
    > response.write "<tr><td>" & Rs.fields("mydatafield") & "</
    > td></tr>"
    > Rs.movenext
    > wend
    >
    > response.write "</table>"
    > end if
    >
    > set rs=nothing
    > Cn.close
    sloan, Nov 19, 2008
    #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. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,379
    Carl Prothman [MVP]
    Jan 12, 2005
  2. V Green
    Replies:
    0
    Views:
    840
    V Green
    Feb 5, 2008
  3. PA Bear [MS MVP]
    Replies:
    0
    Views:
    952
    PA Bear [MS MVP]
    Feb 5, 2008
  4. MowGreen [MVP]
    Replies:
    5
    Views:
    2,014
    PA Bear [MS MVP]
    Feb 9, 2008
  5. Open the excel in new page while exporting

    , Aug 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    118
Loading...

Share This Page