Exporting to Excel using new version of Excel

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doogie

    Exporting to Excel using new version of Excel

    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.creat eobject("ADODB. connection")
    set Rs=server.creat eobject("ADODB. recordset")
    Cn.open "MyConnectionSt ring"
    Rs.open "mysqlquery",Cn ,1,3
    Response.Conten tType = "applicatio n/vnd.ms-excel"
    Response.AddHea der "Content-Disposition", "attachment ;
    filename=Test.x lsx"
    if Rs.eof <true then
    response.write "<table border=1>"
    while not Rs.eof
    response.write "<tr><td>" & Rs.fields("myda tafield") & "</
    td></tr>"
    Rs.movenext
    wend

    response.write "</table>"
    end if

    set rs=nothing
    Cn.close
  • sloan

    #2
    Re: Exporting to Excel using new version of Excel

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

    ..........

    You'll find better luck in another newsgroup.

    Maybe this one:
    microsoft.publi c.inetserver.as p.general




    "Doogie" <dnlwhite@dtgne t.comwrote in message
    news:6843ae40-2b71-4814-af78-8eb06d086aaa@y1 8g2000yqn.googl egroups.com...
    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.creat eobject("ADODB. connection")
    set Rs=server.creat eobject("ADODB. recordset")
    Cn.open "MyConnectionSt ring"
    Rs.open "mysqlquery",Cn ,1,3
    Response.Conten tType = "applicatio n/vnd.ms-excel"
    Response.AddHea der "Content-Disposition", "attachment ;
    filename=Test.x lsx"
    if Rs.eof <true then
    response.write "<table border=1>"
    while not Rs.eof
    response.write "<tr><td>" & Rs.fields("myda tafield") & "</
    td></tr>"
    Rs.movenext
    wend
    >
    response.write "</table>"
    end if
    >
    set rs=nothing
    Cn.close

    Comment

    Working...