Connecting Tech Pros Worldwide Forums | Help | Site Map

Exporting to Excel (xlsx files)

Doogie
Guest
 
Posts: n/a
#1: Nov 19 '08
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
Guest
 
Posts: n/a
#2: Nov 19 '08

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.public.inetserver.asp.general






"Doogie" <dnlwhite@dtgnet.comwrote in message
news:b4642af4-70d2-4cd9-9315-7213699d12ab@t2g2000yqm.googlegroups.com...
Quote:
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
%>

Closed Thread