Exporting to Excel (xlsx files)

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

  1. Doogie

    Doogie Guest

    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.xlsx"
    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=VBScript %>
    <%
    dim Cn,Rs
    set Cn=server.createobject("ADODB.connection")
    set Rs=server.createobject("ADODB.recordset")
    Cn.open "Our Connection String"
    Rs.open "A sql query",Cn,1,3
    Response.ContentType = "application/vnd.ms-excel"
    Response.AddHeader "Content-Disposition", "attachment;
    filename=SomeFileName.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
    %>
    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:...
    > 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.xlsx"
    > 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=VBScript %>
    > <%
    > dim Cn,Rs
    > set Cn=server.createobject("ADODB.connection")
    > set Rs=server.createobject("ADODB.recordset")
    > Cn.open "Our Connection String"
    > Rs.open "A sql query",Cn,1,3
    > Response.ContentType = "application/vnd.ms-excel"
    > Response.AddHeader "Content-Disposition", "attachment;
    > filename=SomeFileName.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, Nov 19, 2008
    #2
    1. Advertising

  3. Doogie

    Semio Semio Guest

    Classic ASP !!.. just the style then..

    Sloan,

    Do you known the diff between ASP.Net & Classic one !!!

    This is ASP.NEt Inline code.. it's not mandatory
    to have the .vb class file to make .Net code !
    You can always use the <% %> tag. May be not
    a good chose but sometime useful !

    Semio
    Semio Semio, Dec 23, 2008
    #3
  4. Doogie

    Neil Guest

    Re: Classic ASP !!.. just the style then..

    "Mark Rae [MVP]" wrote:

    > "Semio Semio" wrote in message news:...
    >
    > > Do you known the difference between ASP.Net & ASP Classic?

    >
    > He does - do you...?
    >
    > > This is ASP.NEt Inline code..

    >
    > No it's not - it's ASP Classic.
    >
    > > it's not mandatory to have the .vb class file to make .Net code!
    > > You can always use the <% %> tag. May be not
    > > a good choice but sometimes useful!

    >
    > That's correct, but irrelevant in this case...
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >

    Looks like vb script to me...
    Neil, Mar 16, 2009
    #4
    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. Doogie

    Exporting to Excel (xlsx files)

    Doogie, Nov 19, 2008, in forum: ASP General
    Replies:
    5
    Views:
    797
    Mike Brind
    Nov 20, 2008
Loading...

Share This Page