Exporting to Excel (xlsx files)

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

    #1

    Exporting to Excel (xlsx files)

    Hi, I am writing a script to export data to an excel file which works
    fine but I've seen one thing that is confusing. If I use the
    extension .xlsx, the file will get created, but Excel won't let me
    open it (although I have the new version of Office in my machine and
    have opened other .xlsx files before). If I save it as .xls it saves/
    opens just fine.

    The error I get is "Excel cannot open the file "SomeFileName.x lsx"
    because the file format or file extension is not valid. Verify that
    the file has not been corrupted and that the file extension matches
    the format of the file".

    Does anyone know why this is occurring?

    <%@ Language=VBScri pt %>
    <%
    dim Cn,Rs
    set Cn=server.creat eobject("ADODB. connection")
    set Rs=server.creat eobject("ADODB. recordset")
    Cn.open "Our Connection String"
    Rs.open "A sql query",Cn,1,3
    Response.Conten tType = "applicatio n/vnd.ms-excel"
    Response.AddHea der "Content-Disposition", "attachment ;
    filename=SomeFi leName.xlsx"

    if Rs.eof <true then
    response.write "<table border=1>"
    while not Rs.eof
    response.write "<tr><td>" & Rs.fields("Some Field") & "</td></tr>"
    Rs.movenext
    wend
    response.write "</table>"
    end if

    set rs=nothing
    Cn.close
    %>
  • sloan

    #2
    Re: Exporting to Excel (xlsx files)

    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:b4642af4-70d2-4cd9-9315-7213699d12ab@t2 g2000yqm.google groups.com...
    Hi, I am writing a script to export data to an excel file which works
    fine but I've seen one thing that is confusing. If I use the
    extension .xlsx, the file will get created, but Excel won't let me
    open it (although I have the new version of Office in my machine and
    have opened other .xlsx files before). If I save it as .xls it saves/
    opens just fine.
    >
    The error I get is "Excel cannot open the file "SomeFileName.x lsx"
    because the file format or file extension is not valid. Verify that
    the file has not been corrupted and that the file extension matches
    the format of the file".
    >
    Does anyone know why this is occurring?
    >
    <%@ Language=VBScri pt %>
    <%
    dim Cn,Rs
    set Cn=server.creat eobject("ADODB. connection")
    set Rs=server.creat eobject("ADODB. recordset")
    Cn.open "Our Connection String"
    Rs.open "A sql query",Cn,1,3
    Response.Conten tType = "applicatio n/vnd.ms-excel"
    Response.AddHea der "Content-Disposition", "attachment ;
    filename=SomeFi leName.xlsx"
    >
    if Rs.eof <true then
    response.write "<table border=1>"
    while not Rs.eof
    response.write "<tr><td>" & Rs.fields("Some Field") & "</td></tr>"
    Rs.movenext
    wend
    response.write "</table>"
    end if
    >
    set rs=nothing
    Cn.close
    %>

    Comment

    Working...