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. Advertisements

  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. Advertisements

  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. Advertisements

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. Ravindra
    Replies:
    0
    Views:
    841
    Ravindra
    Dec 14, 2005
  2. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,586
    Carl Prothman [MVP]
    Jan 12, 2005
  3. David Thielen
    Replies:
    3
    Views:
    79,453
    David Thielen
    May 27, 2008
  4. mavrick_101

    Reading .xlsx

    mavrick_101, Oct 8, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    571
    Cowboy \(Gregory A. Beamer\)
    Oct 9, 2008
  5. Doogie
    Replies:
    1
    Views:
    650
    sloan
    Nov 19, 2008
  6. Madison

    Upload XLSX file

    Madison, Sep 17, 2009, in forum: ASP .Net
    Replies:
    8
    Views:
    3,821
  7. Doogie

    Exporting to Excel (xlsx files)

    Doogie, Nov 19, 2008, in forum: ASP General
    Replies:
    5
    Views:
    1,444
    Mike Brind
    Nov 20, 2008
  8. Ryan

    dynamic XLSX files from a web page

    Ryan, Apr 23, 2009, in forum: ASP General
    Replies:
    1
    Views:
    1,339
    Steven Cheng
    Apr 23, 2009
Loading...