Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Exporting to Excel using new version of Excel

Reply
Thread Tools

Exporting to Excel using new version of Excel

 
 
Doogie
Guest
Posts: n/a
 
      11-19-2008
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.createobject("ADODB.connection")
set Rs=server.createobject("ADODB.recordset")
Cn.open "MyConnectionString"
Rs.open "mysqlquery",Cn,1,3
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;
filename=Test.xlsx"
if Rs.eof <> true then
response.write "<table border=1>"
while not Rs.eof
response.write "<tr><td>" & Rs.fields("mydatafield") & "</
td></tr>"
Rs.movenext
wend

response.write "</table>"
end if

set rs=nothing
Cn.close
 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      11-19-2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.createobject("ADODB.connection")
> set Rs=server.createobject("ADODB.recordset")
> Cn.open "MyConnectionString"
> Rs.open "mysqlquery",Cn,1,3
> Response.ContentType = "application/vnd.ms-excel"
> Response.AddHeader "Content-Disposition", "attachment;
> filename=Test.xlsx"
> if Rs.eof <> true then
> response.write "<table border=1>"
> while not Rs.eof
> response.write "<tr><td>" & Rs.fields("mydatafield") & "</
> td></tr>"
> Rs.movenext
> wend
>
> response.write "</table>"
> end if
>
> set rs=nothing
> Cn.close



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Where to get stand alone Dot Net Framework version 1.1, version2.0, version 3.0, version 3.5, version 2.0 SP1, version 3.0 SP1 ? MowGreen [MVP] ASP .Net 5 02-09-2008 01:55 AM
Re: Where to get stand alone Dot Net Framework version 1.1, version 2.0, version 3.0, version 3.5, version 2.0 SP1, version 3.0 SP1 ? PA Bear [MS MVP] ASP .Net 0 02-05-2008 03:28 AM
Re: Where to get stand alone Dot Net Framework version 1.1, version 2.0, version 3.0, version 3.5, version 2.0 SP1, version 3.0 SP1 ? V Green ASP .Net 0 02-05-2008 02:45 AM
Open the excel in new page while exporting chandra82_tech@yahoo.com ASP .Net Web Controls 0 08-21-2006 07:37 PM
exporting an excel file from database; making changes to excel file and updating the database by importing it back Luis Esteban Valencia ASP .Net 1 01-12-2005 12:28 AM



Advertisments